[Unit testing Rxjs] Confirm subscription points with marble testing (expectSubscriptions)
const { TestScheduler } = require("rxjs/testing");
const { map } = require("rxjs/operators");
const { concat } = require("rxjs");
describe("Marble testing in Rxjs", () => {
let testScheduler;
beforeEach(() => {
testScheduler = new TestScheduler((actual, expected) => {
expect(actual).toEqual(expected);
});
});
it("should let you identify subscription points", () => {
testScheduler.run((helpers) => {
const { cold, expectObservable, expectSubscriptions } = helpers;
const source$ = cold("-a---b-|");
const second$ = cold("-c---d-|");
const final$ = concat(source$, second$);
const expected = "-a---b--c---d-|";
const sourceExpectedSub = "^-- -- --!";
const secondExpectedSub = "-- -- -- -^-- -- --!";
expectObservable(final$).toBe(expected);
expectSubscriptions(source$.subscriptions).toBe(sourceExpectedSub);
expectSubscriptions(second$.subscriptions).toBe(secondExpectedSub);
});
});
});