0

In my test case, I am trying use spyon and call the dialog, but it still says 'Statement not covered' in the coverage report in the line where we are opening the dialog(this._dialog.open(MyDialogComponent) Is there any correct way of doing spyon on Matdialog? How can we spyon different methods like, afterClosed, 'open' and other dialog methods at the same time.

component.ts
 openDialog() {
   this.form.updateValueAndValidity();
    this._dialog.open(MyDialogComponent, {
      data: {
        id: 'abc',
        amt: 222,
        name: 'john'
      },
    });
  }
 
 component.spec.ts
 
 it('should call handleSubmit and Dialog have been called', () => {
  component['_buildForm']();
  spyOn(component['_dialog'], 'open')
    .and
    .returnValue({
        afterClosed: () => of(true),
    } as MatDialogRef<typeof component>);
  component.openDialog();
  });
user1015388
  • 1,283
  • 4
  • 25
  • 45

1 Answers1

0

Try to mock MyDialogComponent and use that mock class as provider for this test file.

Follow this thread