我在 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
is Component
不是Module
,所以它必须在声明中:
TestBed.configureTestingModule({
declarations: [AppComponent, HomeModuleComponent],
imports : [ ]
});
然后您可以创建要测试的组件,
TestBed.createComponent(AppComponent);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)