Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
590 views
in Technique[技术] by (71.8m points)

javascript - 取消订阅后,Jest测试用例将关闭ngdestroy上的对话框(Jest test case to close dialog box on ngdestroy after unsubscribe)

I need to write the jest test case on ng destroy after unsubscribe.

(取消订阅后,我需要在ng destroy上编写开玩笑的测试用例。)

But test is not passing giving me error close is not a method.

(但是测试没有通过给我错误关闭不是一种方法。)

ts file

(ts文件)

ngOnDestroy() {
    this.subscriptions.forEach(subscription => subscription.unsubscribe());
    if (this.dialogRef) {
      this.dialogRef.close();
    }

spec file

(规格文件)

 //Mocking MatDialogRef from angular material
    const dialogReference = {
        afterOpen: () => Observable.of(),
        beforeClose: () => Observable.of(),
        close: () => Observable.of()
      };


      it('function should close the dialog on ngOnDestroy', () => {
          component.ngOnDestroy();
          fixture.detectChanges();
          //const dialogCloseSpy = spyOn(dialogReference, 'close').and.callThrough();
          expect(component['dialogReference'].close()).toHaveBeenCalled();
        });
  ask by Mike Phils translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...