使用管道号案例业力来加载组件失败
当我移除管道时,测试通过
然而,在应用程序中一切正常
以下是我在模板中使用管道的方法
{{ facture | number:'0.2':'fr' }}
或
{{ facture | currency:'EUR':'symbol':'0.2-2':'fr' }}
如果我把每个测试通过,除了我没有得到正确的格式
{{ facture }}
这是我的测试配置
import { CurrencyPipe, DecimalPipe, PercentPipe } from '@angular/common';
fdescribe('MontantFacturesComponent', () => {
const contentTitle: String = 'Choisissez les factures à payer' ;
const facturesUpdate: String = '30 Octobre 2018 à 18:52:48' ;
const factureTotal: String = '232,40' ;
let component: MontantFacturesComponent;
let fixture: ComponentFixture<MontantFacturesComponent>;
let componentEL: DebugElement ;
let contentTitleEL: DebugElement ;
let nomClient: DebugElement ;
let numClient: DebugElement ;
let factureHead: DebugElement ;
let factureBody: DebugElement ;
let factureFoot: DebugElement ;
beforeEach(async(() => {
const comp = TestBed.configureTestingModule({
imports: [
NgbModule.forRoot(),
AngularFontAwesomeModule,
RouterModule.forRoot(<Routes>[]),
HttpClientModule,
],
declarations: [
MontantFacturesComponent,
],
providers : [
AppService,
{provide: APP_BASE_HREF, useValue : '/' },
CommonModule,
CurrencyPipe, DecimalPipe, PercentPipe
]
}) ;
// Configure the component with another set of Providers
TestBed.overrideComponent(
MontantFacturesComponent,
{set: {providers: [{provide: AppService, useClass: MockAppService}]}}
);
comp.compileComponents();
}));
有或没有管道提供者和commonModule
没有任何改变
CommonModule,
CurrencyPipe, DecimalPipe, PercentPipe
当我在模板中有管道时,看起来我的整个组件未定义
Uncaught Error: Unexpected module 'CommonModule' declared by the module
'DynamicTestModule'. Please add a @Pipe/@Directive/@Component annotation.
看起来问题是使用本地fr
两者
{{factureTotal | currency:'EUR':'symbol':'0.2-2':'fr'}}
和
{{factureTotal | currency:'EUR':'symbol':'0.2-2':'fr-FR'}}
失败,但
{{factureTotal | currency:'EUR':'symbol':'0.2-2'}}
任何想法如何让业力发挥作用
答案 0 :(得分:3)
在看了一周之后发现了问题
看起来karma没有加载本地格式
import { registerLocaleData } from '@angular/common';
import localeFr from '@angular/common/locales/fr';
registerLocaleData(localeFr);
这解决了导致testComponent崩溃的问题