【发布时间】:2017-02-22 04:57:19
【问题描述】:
我在 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 必须在声明中而不是在导入中。此外,您可以在您的 TestBed 中导入模块吗?谢谢。
标签: unit-testing angular karma-jasmine