我在 Angular 2 中测试 app.component.ts 时遇到问题。我正在使用 angular-cli。每当我运行 ng test 时,我的 app.component.spec.ts 都会在控制台提示错误:
Failed: Unexpected directive 'HomeModuleComponent' imported by the module 'DynamicTestModule'
Error: Unexpected directive 'HomeModuleComponent' imported by the module 'DynamicTestModule'
我在 TestBed 中导入了 HomeModuleComponent
TestBed.configureTestingModule({
declarations: [AppComponent],
imports : [ HomeModuleComponent ]
});
谁能帮我解决这个问题?
最佳答案
HomeModuleComponent
是 Component
而不是 Module
,所以它必须在声明中:
TestBed.configureTestingModule({
declarations: [AppComponent, HomeModuleComponent],
imports : [ ]
});
然后您可以创建要测试的组件,
TestBed.createComponent(AppComponent);
关于unit-testing - Angular 2.0.0 - 测试 "imported by the module ' DynamicTestModule' ",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40014712/