I have a module which stores data in this.store
and takes keyboard events in this.stream
The relationship between this.store and this.stream is as follows
this.stream.subscribe(function(keyCode){
this.store.add(100)
});
Now I am writing test cases against those events. I want to know when I click the keyboard 3 times respectively what will the intermediate results be.
So the test case is as follows:
var keyboardSource = Rx.Observable.create(function(observer) {
observer.onNext({
keyCode: defaultValidOption.default.keyboardData[0]
});
observer.onNext({
keyCode: defaultValidOption.default.keyboardData[1]
});
observer.onNext({
keyCode: defaultValidOption.default.keyboardData[2]
});
});
module.stream.subscribe(x => {
module.store.total.should.equal(300);
done();
});
This is correct because I can get the final result when the entire stream event is fired.
But the following is not correct.
module.stream.bufferWithCount(2).subscribe(x => {
module.store.total.should.equal(200);
done();
});
So how to I delay those events in my test case so that I can get imtermediate results. Thanks.
When testing you should use the
TestScheduler
to explicitly control timings rather than relying on whatever the defaults are. So I would recommend you change your test code to: