Unit Testing MatDialog Open gives SPEC HAS NO EXPECTATIONS should call openDialog

30 views Asked by At

I would like to do Unit Testing for Mat Open Dialog. The dialog opens when clicked on the button in the main page, the code for dialog is also in the same page(not injected). I am also using Mockito(not Jest) . New to unit testing , so need help.FOllowing the the test code. Tests passes but saying SPEC HAS NO EXPECTATIONS should call openDialog

 {
  provide: MAT_DIALOG_DATA, 
  useValue: {}
}, 
{ provide: MatDialogRef, 
  useValue: {}
}
it('should call openDialog', () => {
  const fixture = TestBed.createComponent(abcComponent);
  const app = fixture.componentInstance;
  app.openDialog();
}) 
1

There are 1 answers

2
Refel On

you need to add expectation of test. example:

in your case

expect(app.openDialog).toHaveBeenCalled()

But I suggest you have to unit test every function.

it('should test openDialog function') {
// your test case here
}