jeudi 11 février 2021

How to test Angular Material Dialog

I am trying to figure out the best way to test a component that uses Angular Material Dialog (https://material.angular.io/components/dialog/overview)

I am using the built in testing utils from Angular (Karma, jasmine)

public deleteQualification: void() {
   let dialogRef = dialog.open(DeleteQualificationComponent, {
      height: '400px',
      width: '600px',
   });

    dialogRef.afterClosed().subscribe(result => {
          if (result){
             //delete code goes here, I want to test this
            }
   });
   
}

I'm not sure how to mock up a object that returns a observable, and then wait the response in the test..

Currently I've solved it this way:

public deleteQualification: void() {
   let dialogRef = dialog.open(DeleteQualificationComponent, {
      height: '400px',
      width: '600px',
   });

    dialogRef.afterClosed().subscribe(result => {
          if (result){
             doDelete();
            }
   });

}



//I only test this
   public doDelete:void(){

   }

Aucun commentaire:

Enregistrer un commentaire