Sometimes we have functions, which modifies original source using async operators like delay.
Lets assume we have something really simple:
// Old syntax
function modify(source) {
return source.delay(1000);
}
I am using marbles to test RxJs, so my test looks like:
it("mock chain style call (modify function)", function() {
var values = {
a: "test",
x: "test"
};
var source = hot( "-a", values);
var delayTime = time( "--|");
var result = cold( "---x", values);
var originalDelay = Rx.Observable.prototype.delay;
spyOn(Rx.Observable.prototype, "delay").and.callFake(function () {
return originalDelay.call(this, delayTime, jm.getTestScheduler());
});
expect(modify(source)).toBeObservable(result);
});
It's pretty the same what is used in rxjs library for testing: https://github.com/ReactiveX/rxjs/blob/master/spec/operators/delay-spec.ts
But we have to patch Observable.delay function, because we don't have direct access to it. And it works good.
But we decided to start using pipeable operators from RxJs. Is there any ideas how test for this function:
// New syntax
function modify(source) {
return source.pipe(Rx.operators.delay(1000));
}
could look like?