in my code I have a function that uses fromEvent, that is an Observable
getNavigatorStatus(): Observable<any> {
return merge(
fromEvent(window, 'offline').pipe(map(() => false)),
fromEvent(window, 'online').pipe(map(() => true)),
Observable.create(sub => {
sub.next(navigator.onLine);
sub.complete();
})
);
}
and have this test:
it('getNavigatorStatus: should returns Observable', done => {
spyOn(Observable, <any>'fromEvent').and.returnValue(of({}));
spyOn(Observable, 'create').and.returnValue(of({}));
NetworkService.getNavigatorStatus().subscribe(() => {
expect(fromEvent).toHaveBeenCalledWith(window, 'offline');
expect(fromEvent).toHaveBeenCalledWith(window, 'online');
expect(Observable.create).toHaveBeenCalled();
done();
});
});
my problem is after migrating to angular 6, I can no longer spyOn fromEvent in the Observable like I used to do before angular 6.
spyOn(Observable, <any>'fromEvent').and.returnValue(of({}));
I need help to test the call of fromEvent (parameters, result, etc) inside my getNavigatorStatus function.
Aucun commentaire:
Enregistrer un commentaire