I have a webapp project which uses rxjs5 to implement a flux and I am currently looking for solutions to write unit tests on it.
In fact, I have 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 way and write something like (i took a sample example from 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 marble testing method (with operators like hot
, cold
and so on...) outside the rxjs5 project. I don't figure out how to use this nice tool in my project.
Thank you for your help.
Aucun commentaire:
Enregistrer un commentaire