Angular: How to mock MatDialogRef while testing

前端 未结 4 2240
隐瞒了意图╮
隐瞒了意图╮ 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条回答
  •  广开言路
    2021-02-18 14:34

    I solved it by changing the component constructor to:

    constructor(
      public dialogRef: MatDialogRef,
      @Inject(MAT_DIALOG_DATA) public data: Dialog | any
    )
    

    The providers in the TestBed were:

    providers: [{ provide: MatDialogRef, useValue: {} }, { provide: MAT_DIALOG_DATA, useValue: data }]
    

提交回复
热议问题