他们计划添加EntryComponents
到测试模块接口.请参阅问题:https://github.com/angular/angular/issues/10760
有关当前的解决方法,请参阅Angular Material库,请参阅https://github.com/angular/material2/blob/master/src/lib/dialog/dialog.spec.ts#L479.
基本上,他们动态创建一个真实的模块,然后导入它进行测试.
// Create a real (non-test) NgModule as a workaround for // https://github.com/angular/angular/issues/10760 const TEST_DIRECTIVES = [ ComponentWithChildViewContainer, PizzaMsg, DirectiveWithViewContainer, ContentElementDialog ]; @NgModule({ imports: [MdDialogModule], exports: TEST_DIRECTIVES, declarations: TEST_DIRECTIVES, entryComponents: [ComponentWithChildViewContainer, PizzaMsg, ContentElementDialog], }) class DialogTestModule { }
现在你可以使用了 DialogTestModule
beforeEach(async(() => { TestBed.configureTestingModule({ imports: [MdDialogModule.forRoot(), DialogTestModule] ...