Angular 2.0.0-测试“由模块"DynamicTestModule"导入 [英] Angular 2.0.0 - Testing " imported by the module 'DynamicTestModule' "
本文介绍了Angular 2.0.0-测试“由模块"DynamicTestModule"导入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Angular 2中测试app.component.ts时遇到问题.我在使用angular-cli.每当我运行ng test时,我的app.component.spec.ts都会在控制台提示符下显示错误:
I am having a problem in testing app.component.ts in Angular 2. I am using angular-cli. Whenever I run ng test, my app.component.spec.ts makes the console prompt with the error:
Failed: Unexpected directive 'HomeModuleComponent' imported by the module 'DynamicTestModule'
Error: Unexpected directive 'HomeModuleComponent' imported by the module 'DynamicTestModule'
我将HomeModuleComponent导入了TestBed
I imported the HomeModuleComponent in TestBed
TestBed.configureTestingModule({
declarations: [AppComponent],
imports : [ HomeModuleComponent ]
});
有人可以帮助我解决这个问题吗?
Can anyone help me with this problem?
推荐答案
HomeModuleComponent
是Component
而不是Module
,因此它必须在声明中:
HomeModuleComponent
is Component
not the Module
, so it has to be in declarations:
TestBed.configureTestingModule({
declarations: [AppComponent, HomeModuleComponent],
imports : [ ]
});
然后您可以创建要测试的组件,
and then you can create the component to test as,
TestBed.createComponent(AppComponent);
这篇关于Angular 2.0.0-测试“由模块"DynamicTestModule"导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文