Warning
This package relates to the rx
package at v4. It will not work with the newer rxjs
package which refers to Rx v5 and above.
ChaiRx extends Chai with a simple utility method emit
for testing emits from an RxJS Observable stream using the Rx.TestScheduler
.
import Rx from "rx";
import chai from "chai";
import chaiRx from "chai-rx";
chai.use(chaiRx);
const { onNext, onCompleted } = Rx.ReactiveTest;
const scheduler = new Rx.TestScheduler();
const 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
const output = scheduler.startScheduler(() => xs.map((x) => x * x), {
created: 100,
subscribed: 200,
disposed: 300,
});
expect(output).to.emit([onNext(210, 4), onNext(220, 9), onCompleted(230)]);
const xs = scheduler.createHotObservable(
onNext(250, { foo: "bar" }),
onError(300, new Error("An error"))
);
const output = scheduler.startScheduler(() => xs);
// expect
expect(output).to.emit([
onNext(250, { foo: "bar" }),
onError(300, ({ error }) => error.message === "An error"),
]);
// should
output.should.emit([
onNext(250, { foo: "bar" }),
onError(300, ({ error }) => error.message === "An error"),
]);
const const xs = scheduler.createHotObservable(onNext(250));
const output = scheduler.startScheduler(() => xs);
// with `not`
expect(output).to.not.emit([
onNext(300)
]);
npm install chai-rx
import chai from "chai";
import chaiRx from "chai-rx";
chai.use(chaiRx);
var chai = require("chai");
var chaiRx = require("chai-rx");
chai.use(chaiRx);
If you include ChaiRx directly with a <script>
tag, after the one for Chai itself, then it will automatically plug in to Chai and be ready for use:
<script src="chai.js"></script>
<script src="chai-rx.js"></script>