【发布时间】:2017-07-12 21:21:49
【问题描述】:
我正在使用 Angular CLI 1.0.0-beta.32.2 并正在为 Angular 2 服务编写单元测试,该服务动态创建一个组件并将其插入另一个组件。
在我的单元测试中,我尝试创建一个模拟组件来测试我的服务,但是ng test 的输出抛出一个错误,说明我的模拟组件是在entryComponents 属性中指定的。当我尝试将组件添加到 TestModuleMetadata 对象的 entryComponents 属性中时,如下所示:TestBed.createTestingModule({...entryComponents: [ TestDialogComponent ]...}) 我看到以下错误,指出 entryComponents 属性不存在。
Chrome 56.0.2924 (Windows 10 0.0.0) DialogService should create a child component when opening FAILED
Error: No component factory found for TestDialogComponent. Did you add it to @NgModule.entryComponents?
查看 TestModuleMetadata 定义表明 entryComponents 属性不存在。那么如何在 Angular 2 和 Jasmine 的单元测试中动态创建组件呢?
【问题讨论】:
标签: unit-testing angular typescript angular-cli