Pat*_*ler 3 jasmine typescript ngx-translate angular
我有一个使用 ngx-translate 进行本地化的组件。创建模块的基本单元测试不起作用。它失败并出现以下错误:
PatientDataComponent should create FAILED
[ERROR ->]{{ 'patient.information' | translate }}
</p>
The pipe 'translate' could not be found ("<p>[ERROR ->]{{ 'patient.information' | translate }}</p>"): ng:///DynamicTestModule/PatientDataComponent.html@1:2
error properties: Object({ ngSyntaxError: true, ngParseErrors: [ The pipe 'translate' could not be found ("<p>"): ng:///DynamicTestModule/PatientDataComponent.html@1:2 ] })
Run Code Online (Sandbox Code Playgroud)
该应用程序能够切换语言;因此 ngx-translate 似乎有效。除了我的单元测试。测试代码如下:
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { PatientDataComponent } from './patient-data.component';
describe('PatientDataComponent', () => {
let component: PatientDataComponent;
let fixture: ComponentFixture<PatientDataComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [PatientDataComponent]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(PatientDataComponent);
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
Run Code Online (Sandbox Code Playgroud)
我需要做什么来解决此错误并使组件可测试?
在您的 testBed 配置中添加,imports就像TranslateModule您在 appModule 或声明组件的模块中一样。例如:
TestBed.configureTestingModule({
declarations: [PatientDataComponent],
imports: [
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: I18nHttpLoaderFactory,
deps: [HttpClient],
},
}),
],
}).compileComponents();
Run Code Online (Sandbox Code Playgroud)
也许您有其他翻译配置。
| 归档时间: |
|
| 查看次数: |
8397 次 |
| 最近记录: |