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
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…