Angular: How to mock MatDialogRef while testing

前端 未结 4 2258
隐瞒了意图╮
隐瞒了意图╮ 2021-02-18 13:56

I have a DialogComponent that has the following constructor where Dialog is a custom object:

constructor(
    public dialogRef: MatDialogRef

        
4条回答
  •  -上瘾入骨i
    2021-02-18 14:28

    Import MatDialogModule and MatDialogRef from angular/material/dialog instead of angular/material. Import the ModalDialogModule and provide providers for MatDialogRef in your TestBed.

    Import {MatdialogModule,MatDialogRef} from '@angular/material/dialog';
    
    TestBed.configureTestingModule({
    declarations: [componentName],
    imports: [MatdialogModule],
    providers: [{provide : MatDialogRef, useValue : {}}]
    });
    

提交回复
热议问题