Pas*_*cal 7 jasmine karma-runner angular
使用Pipe Number case karma来加载组件失败
当我移除管道时,测试通过
但是在应用程序中一切正常
这是我在模板中使用管道的方法
{{ facture | number:'0.2':'fr' }}
Run Code Online (Sandbox Code Playgroud)
要么
{{ facture | currency:'EUR':'symbol':'0.2-2':'fr' }}
Run Code Online (Sandbox Code Playgroud)
如果我把每个测试通过,除了我没有得到正确的格式
{{ facture }}
Run Code Online (Sandbox Code Playgroud)
这是我的测试配置
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();
}));
Run Code Online (Sandbox Code Playgroud)
有或没有管道供应商,commonModule没有任何变化
CommonModule,
CurrencyPipe, DecimalPipe, PercentPipe
Run Code Online (Sandbox Code Playgroud)
当我在模板中有管道时,看起来我的整个组件都未定义
Uncaught Error: Unexpected module 'CommonModule' declared by the module
'DynamicTestModule'. Please add a @Pipe/@Directive/@Component annotation.
Run Code Online (Sandbox Code Playgroud)
看起来问题是使用本地 fr
都
{{factureTotal | currency:'EUR':'symbol':'0.2-2':'fr'}}
Run Code Online (Sandbox Code Playgroud)
和
{{factureTotal | currency:'EUR':'symbol':'0.2-2':'fr-FR'}}
Run Code Online (Sandbox Code Playgroud)
失败但是
{{factureTotal | currency:'EUR':'symbol':'0.2-2'}}
Run Code Online (Sandbox Code Playgroud)
任何想法如何让业力发挥作用都很好
查看一周后发现问题
看来业力没有加载本地格式
import { registerLocaleData } from '@angular/common';
import localeFr from '@angular/common/locales/fr';
registerLocaleData(localeFr);
Run Code Online (Sandbox Code Playgroud)
这解决了导致 testComponent 崩溃的问题
| 归档时间: |
|
| 查看次数: |
238 次 |
| 最近记录: |