title: Cannot read property 'afterClosed' of undefined when unit testing MatDialog in Jasmine
body: <p>I get the following error from Karma Jasmine:<br>
  <code>TypeError: Cannot read property 'afterClosed' of undefined</code></p>
  
  <p>I searched sincerely, but I could not find a solution in Stack Overflow or in other sources.</p>
  
  <p>This is how I open the <code>MatDialog</code> in my component:<br >
  (Like <a href="https://material.angular.io/components/dialog/overview" rel="noreferrer">documented</a>)</p>
  
  <pre><code>constructor(public dialog: MatDialog) {}
  
  public openDialog(): void {
      const dialogReference: MatDialogRef&lt;any, any&gt; = this.dialog.open(myDialogComponent, {
          width: '1728px'
      });
  
      dialogReference.afterClosed().subscribe((result) =&gt; {
      });
  }
  </code></pre>
  
  <p>This is my unit test config:</p>
  
  <pre><code>beforeEach(async(() =&gt; {
      TestBed.configureTestingModule({
          declarations: [
              myRequestComponent
          ],
          imports: [
              MatDialogModule,
              ReactiveFormsModule
          ],
          providers: [
              { provide: MatDialog, useValue: {} },
          ],
          schemas: [CUSTOM_ELEMENTS_SCHEMA]
      }).compileComponents();
  }));
  
  beforeEach(() =&gt; {
      fixture = TestBed.createComponent(myRequestComponent);
      component = fixture.componentInstance;
      fixture.detectChanges();
  });
  </code></pre>
  
  <p>Here is my unit test:</p>
  
  <pre><code>it('openDialog() should open a dialog', () =&gt; {
      spyOn(component.dialog, 'open');
  
      component.openDialog();
  
      expect(component.dialog.open).toHaveBeenCalled();
  });
  </code></pre>
  
  <p>Do I have to mock the MatDialog or the MatDialogReference?</p>