我正在尝试使用Angular 4项目中的karma / jasmine进行单元测试。我选了一个组件,它位于组件树的最底层,因此我不会有很多依赖项。
但不幸的是我仍然有问题,我收到的错误是添加了未导入的组件,但是当我添加它时,它要求另一个,而不是另一个,依此类推。我添加了其中的5个但仍然没有,我想我甚至不应该导入组件,这些组件完全没有连接到单元测试...
示例错误:
Error: Component ReportSelection is not part of any NgModule or the module has not been imported into your module.
如何避免这样的事情?
当前的beforeEach()注释掉了一些不相关的组件:
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [
InternalUserAccountSelectionComponent, ExactLengthValidatorDirective,
//ReportSelection, ReportViewComponent, FrameComponent, DemoComponent, ItalyAnnualCommissionComponent
],
imports: [
HttpModule, FormsModule, TooltipModule.forRoot(), TypeaheadModule.forRoot(), AppRoutingModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: HttpLoaderFactory,
deps: [Http]
}
}),
],
providers: [
TranslateService, Api, Serializerer, Alert, LocalStorageService, BrowserCheck, SecurityService
],
});
fixture = TestBed.createComponent(InternalUserAccountSelectionComponent);
comp = fixture.componentInstance;
});