I am using RxJs to count how many packets arrive in a particular time window. My code basically looks like this:
var packetSubject = new Rx.Subject();
var packetsInWindow = [];
function startMonitoring() {
var subscription = packetSubject
.windowWithTime(1000)
.select(function(window) {
window.toArray().subscribe(function(elements) {
packetsInWindow.push(elements.length);
});
})
.subscribe();
}
function newPacket(packet) {
packetSubject.onNext(packet);
}
How to unit test this code using Rx TestScheduler? I could not find any suitable example for testing Subjects.
Have a look this example :
https://emmkong.wordpress.com/2015/03/18/how-to-unit-test-rxjs-throttle-with-rx-testscheduler/