Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
592 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 Reply

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...