我有一个模式,一旦用户选择页面的菜单选项,就会打开该模式。我遇到的问题是我不知道如何让它在我的 ngOnInit
test.component.ts
constructor(public dialog: MdDialog) { }
ngOnInit() {
this.openTestModal();
}
openTestModal() {
this.dialog.open(TestModalComponent, {
disableClose: true,
width: '600px'
});
}
我已经导入了我的模型组件并尝试了:
更改密码.component.spec.ts
import { TestModalComponent } from '../test-modal/test-modal.component';
spyOn(component, 'openTestModal');
spyOn(component, 'ngOnInit').and.callThrough();
it('should be created', () => {
expect(component).toBeTruthy();
});
错误
No component factory found for TestComponent. Did you add it to @NgModule.entryComponents?
但它已经在那里了
最佳答案
要解决此问题,请在测试结束时使用 EntryComponents 将 TestComponent 添加到模块中。
@NgModule({
declarations: [TestComponent],
entryComponents: [
TestComponent,
],
})
class TestModule {}
并将 TestModule 添加到 testBed 导入中。
关于unit-testing - Angular 2 - Jasmine 测试 - 在页面加载时打开模态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45501912/