Angular material: How to test if is called

angular 9

I implemented mat-dialog with following angular material example

  openDialog() {
    const dialogRef =;

    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, 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



but test said

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

why it said that error even if actually script calls .
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 is called