Rx.TestScheduler
Usage ##
function createMessage(actual, expected) {
return 'Expected: [' + expected.toString() + ']\r\nActual: [' + actual.toString() + ']';
}
// Using QUnit testing for assertions
var collectionAssert = {
assertEqual: function (expected, actual) {
var comparer = Rx.Internals.isEqual,
isOk = true;
if (expected.length !== actual.length) {
ok(false, 'Not equal length. Expected: ' + expected.length + ' Actual: ' + actual.length);
return;
}
for(var i = 0, len = expected.length; i < len; i++) {
isOk = comparer(expected[i], actual[i]);
if (!isOk) {
break;
}
}
ok(isOk, createMessage(expected, actual));
}
};
var onNext = Rx.ReactiveTest.onNext,
onCompleted = Rx.ReactiveTest.onCompleted,
subscribe = Rx.ReactiveTest.subscribe;
var scheduler = new Rx.TestScheduler();
// Create hot observable which will start firing
var xs = scheduler.createHotObservable(
onNext(150, 1),
onNext(210, 2),
onNext(220, 3),
onCompleted(230)
);
// Note we'll start at 200 for subscribe, hence missing the 150 mark
var res = scheduler.startWithCreate(function () {
return xs.map(function (x) { return x * x });
});
// Implement collection assertion
collectionAssert.assertEqual(res.messages, [
onNext(210, 4),
onNext(220, 9),
onCompleted(230)
]);
// Check for subscribe/unsubscribe
collectionAssert.assertEqual(xs.subscriptions, [
subscribe(200, 230)
]);Location
TestScheduler Constructor ##
TestScheduler Constructor ##TestScheduler Instance Methods ##
TestScheduler Instance Methods ##Inherited Classes ##
TestScheduler Constructor ##
Rx.TestScheduler()
Rx.TestScheduler()Example
Location
TestScheduler Instance Methods ##
Rx.TestScheduler.prototype.createColdObservable(...args)
Rx.TestScheduler.prototype.createColdObservable(...args)Arguments
Returns
Example
Location
Rx.TestScheduler.prototype.createHotObservable(...args)
Rx.TestScheduler.prototype.createHotObservable(...args)Arguments
Returns
Example
Location
Rx.TestScheduler.prototype.createObserver()
Rx.TestScheduler.prototype.createObserver()Returns
Example
Location
Rx.TestScheduler.prototype.startWithCreate(create)
Rx.TestScheduler.prototype.startWithCreate(create)Arguments
Returns
Example
Location
Rx.TestScheduler.prototype.startWithDispose(create, disposed)
Rx.TestScheduler.prototype.startWithDispose(create, disposed)Arguments
Returns
Example
Location
Rx.TestScheduler.prototype.startWithTiming(create, created, subscribed, disposed)
Rx.TestScheduler.prototype.startWithTiming(create, created, subscribed, disposed)Arguments
Returns
Example
Location
Last updated