I have a simple function that does this
ngOnInit() { if (this.session.getToken()) { this.isUserLogged = true; } this.loadingObserver = this.session.loadingObservable.subscribe(loading => this.isLoading = loading); }
and my test is as follows
it('Testing ngOnInit() ...', async(() => { let spy = spyOn(services.session, 'getToken').and.returnValue('token'); services.session.loadingObservable.subscribe(any => expect(component.isLoading).toEqual(false)); component.ngOnInit(); expect(component.isUserLogged).toEqual(true); expect(spy).toHaveBeenCalled(); }));
But in the scope of my application code, the subscription does not apply. In fact, waiting for fake also works.
Do you have any ideas on testing your subscription?
source share