I have a webapp project that uses rxjs5 to implement flux , and am currently looking for solutions to write unit tests on it.
In fact, I implemented custom observables inside, for example:
function getActivityObservable(events, timeout) { return Observable.create((observer) => { const deb = debounce(() => observer.next(false), timeout || DEFAULT_TIMEOUT); const sub = events.subscribe((e) => { if (!e) { deb.cancel(); observer.next(false); } else { observer.next(true); deb(e); } }); return () => { if (sub) sub.unsubscribe(); if (deb) deb.cancel(); }; }).distinctUntilChanged(); }
I would like to test it using the marble testing method and write something like (I took an example from the rxjs repository)
describe("getActivityObservable", () => { it("should debounce by selector observable", () => { const e1 = hot("--a--bc--d----|"); const e1subs = "^ !"; const expected = "----a---c--d--|"; expectObservable(e1.debounce(getTimerSelector(20))).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); }); });
My question is:
Is it possible to use the marble testing method (with operators like hot , cold , etc.) outside the rxjs5 project. I do not understand how to use this good tool in my project.
Thank you for your help.
javascript unit-testing karma-runner jasmine rxjs5
Alexandre Duros
source share