This is RxJS v 4. Find the latest version here
This class contains test utility methods such as create notifications for testing purposes.
- rx.testing.js
Factory method for an OnCompleted notification record at a given time.
ticks
(Number): Recorded virtual time the OnCompleted notification occurs.
(Recorded): OnCompleted notification.
var onCompleted = Rx.ReactiveTest.onCompleted;
var scheduler = new Rx.TestScheduler();
var xs = scheduler.createHotObservable(
onCompleted(260)
);
var res = scheduler.startScheduler(function () {
return xs.map(function (x) { return x; });
});
// Write custom assertion
collectionAssert.assertEqual(res.messages, [
onCompleted(260)
]);
- rx.testing.js
Factory method for an OnError notification record at a given time with a given error.
ticks
(Number): Recorded virtual time the OnError notification occurs.exception
(Error | Function): Recorded exception stored in the OnError notification or a predicate
(Recorded): Recorded OnError notification.
var ex = new Error('woops');
var onError = Rx.ReactiveTest.onError;
var scheduler = new Rx.TestScheduler();
var xs = scheduler.createHotObservable(
onError(201, ex)
);
var res = scheduler.startScheduler(function () {
return xs.map(function (x) { return x; });
});
// Write custom assertion
collectionAssert.assertEqual(res.messages, [
// Using a predicate
onError(201, function (e) { return e.message === 'woops'; })
]);
- rx.testing.js
Factory method for an OnNext notification record at a given time with a given error.
ticks
(Number): Recorded virtual time the OnNext notification occurs.value
(Any | Function): Recorded exception stored in the OnNext notification or a predicate
(Recorded): Recorded OnNext notification.
var onNext = Rx.ReactiveTest.onNext;
var scheduler = new Rx.TestScheduler();
var xs = scheduler.createHotObservable(
onNext(201, 42)
);
var res = scheduler.startScheduler(function () {
return xs.map(function (x) { return x; });
});
// Write custom assertion
collectionAssert.assertEqual(res.messages, [
// Using a predicate
onNext(201, function (x) { return x === 42; })
]);
- rx.testing.js
Default virtual time used for creation of observable sequences in unit tests. This has a value of 100
.
var scheduler = new Rx.TestScheduler();
var xs = scheduler.createHotObservable(
Rx.ReactiveTest.onNext(201, 42),
Rx.ReactiveTest.onNext(202, 56),
Rx.ReactiveTest.onCompleted(203)
);
var res = scheduler.startScheduler(
function () { return xs.map(function (x) { return x; })},
Rx.ReactiveTest.created,
Rx.ReactiveTest.subscribed,
Rx.ReactiveTest.disposed
);
- rx.testing.js
Default virtual time used to dispose subscriptions in unit tests. This has a value of 1000
.
var scheduler = new Rx.TestScheduler();
var xs = scheduler.createHotObservable(
Rx.ReactiveTest.onNext(201, 42),
Rx.ReactiveTest.onNext(202, 56),
Rx.ReactiveTest.onCompleted(203)
);
var res = scheduler.startScheduler(
function () { return xs.map(function (x) { return x; })},
{
created: Rx.ReactiveTest.created,
subscribed: Rx.ReactiveTest.subscribed,
disposed: Rx.ReactiveTest.disposed
}
);
- rx.testing.js
Default virtual time used to subscribe to observable sequences in unit tests. This has a value of 200
.
var scheduler = new Rx.TestScheduler();
var xs = scheduler.createHotObservable(
Rx.ReactiveTest.onNext(201, 42),
Rx.ReactiveTest.onNext(202, 56),
Rx.ReactiveTest.onCompleted(203)
);
var res = scheduler.startScheduler(
function () { return xs.map(function (x) { return x; })}
);
- rx.testing.js