I have a DialogComponent
that has the following constructor where Dialog
is a custom object:
constructor(
public dialogRef: MatDialogRef<CustomDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: Dialog
)
I created the following TestBed
in Angular4:
data = new Dialog()
data.message = 'Dialog Message'
TestBed.configureTestingModule({
imports: [MaterialModules],
declarations: [CustomDialogComponent],
providers: [MatDialogRef, { provide: Dialog, useValue: data }]
})
TestBed.overrideModule(BrowserDynamicTestingModule, {
set: {
entryComponents: [CustomDialogComponent]
}
})
await TestBed.compileComponents()
But I get the following error:
Failed: Can't resolve all parameters for MatDialogRef: (?, ?, ?).
Error: Can't resolve all parameters for MatDialogRef: (?, ?, ?).
changing providers to:
providers: [
{ provide: MatDialogRef, useValue: {} },
{ provide: MAT_DIALOG_DATA, useValue: data }
]
results in the following error:
Error: No provider for Dialog!
How do I resolve this?