私のテストでは退会できません。 他に誰かがこの問題を抱えていますか? (私は間違って何をやっている?)ngOnDestroy()内の登録を解除できません角度5
基本テスト:
describe('ngOnDestroy()',() => {
it('should unsubscribe if isLoggedInSub is defined', async(() => {
comp.ngOnInit();
fixture.detectChanges();
comp.ngOnDestroy();
fixture.detectChanges();
expect(comp.isLoggedInSub).not.toBeDefined();
}));
});
コンソールエラー:
Uncaught Expected Subscriber({ closed: true, _parent: null, _parents: null, _subscriptions: null, syncErrorValue: null, syncErrorThrown: false, syncErrorThrowable: false, isStopped: true, destination: SafeSubscriber({ closed: false, _parent: null, _parents: null, _subscriptions: null, syncErrorValue: null, syncErrorThrown: false, syncErrorThrowable: false, isStopped: false, destination: Object({ closed: true, next: Function, error: Function, complete: Function }), _parentSubscriber: <circular reference: Object>, _context: <circular reference: Object>, _next: Function, _error: undefined, _complete: undefined }) }) not to be defined.
at Object.testing_3.async
どのようにあなたが 'isLoggedInSub'を作成しているだろうか?あなたの 'ngOnDestroy'メソッドはどのように見えますか? – vincecampanale
'isLoggedInSub:サブスクリプション;' 'isLoggedInSub = someObservableFunction.subscribe(()=> {});' 'ngOnDestroy(){isLoggedInSub.unsubscribe()}' – cuznerdexter