NullInjectorError: No provider for InjectionToken MatDialogData

Try removing MatDialogRef and MAT_DIALOG_DATA from the karma jasmin spec, and the component you need to be dialog import like this:

imports: [
    DynamicModule.withComponents([YOUR_DIALOG_COMPONENT])
]

In the edit dialog component I was passing the data object into the close method. I removed it and the error went away.

Changed this:

this.dialogRef.close(myData);

to this:

 this.dialogRef.close();

in my case, I imported the directives MatDialogModule, MAT_DIALOG_DATA and MatDialogRef

import { MatDialogModule, MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';

and then within beforeEatch():

imports: [ MatDialogModule],
providers: [
    { provide: MAT_DIALOG_DATA, useValue: {} },
    { provide: MatDialogRef, useValue: {} }
  ]