Reputation: 4026
I have a modal which is opened as soon as the user selects the menu option for the page. Isue i'm having is that i have no idea on how to get it to call my function call in my ngOnInit
test.component.ts
constructor(public dialog: MdDialog) { }
ngOnInit() {
this.openTestModal();
}
openTestModal() {
this.dialog.open(TestModalComponent, {
disableClose: true,
width: '600px'
});
}
I have imported my model component and tried:
change-password.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();
});
Error
No component factory found for TestComponent. Did you add it to @NgModule.entryComponents?
but its already in there
Upvotes: 2
Views: 2889
Reputation: 1182
To solve this add your TestComponent to a module at end of your test with entryComponents.
@NgModule({
declarations: [TestComponent],
entryComponents: [
TestComponent,
],
})
class TestModule {}
and add TestModule to the testBed imports.
Upvotes: 4