Angular material: How to test if dialog.open() is called

angular 9

I implemented mat-dialog with following angular material example

https://stackblitz.com/angular/jdvaxxxqoqo?file=src%2Fapp%2Fdialog-content-example.ts


  openDialog() {
    const dialogRef = this.dialog.open(DialogContentExampleDialog);

    dialogRef.afterClosed().subscribe(result => {
      console.log(`Dialog result: ${result}`);
    });
  }

it worked well, but I couldn’t figure out how to test openDialog function.

What I should test might be, dialog.open is called, so I tried was


it('should dialog open called',() => {
   // create a spy to check if dialog open is called or not 
   const spyObject = spyOn(Component.dialog,'open').and.callThrough();
   
   // call that function
   component.openDialog();

   expect(spyObject).toHaveBeenCalled();

})

but test said

Error: <spyOn> : open() method does not exist
Usage: spyOn(<object>, <methodName>)

why it said that error even if actually script calls this.dialog.open() .
And what is a way to test it ?

Thank you for your kind help

Source: New feed
Source Url Angular material: How to test if dialog.open() is called