[Unit testing RxJS] Test synchronous operations

const { TestScheduler } = require("rxjs/testing");
const { map, take } = require("rxjs/operators");
const { concat, from } = require("rxjs");

describe("Marble testing in Rxjs", () => {
  let testScheduler;

  beforeEach(() => {
    testScheduler = new TestScheduler((actual, expected) => {
      expect(actual).toEqual(expected);
    });
  });

  it("should let you test asychronous operations", () => {
    testScheduler.run((helpers) => {
      const { expectObservable } = helpers;
      const source$ = from([1, 2, 3]);
      const expected = "(abc|)";
      expectObservable(source$).toBe(expected, { a: 1, b: 2, c: 3 });
    });
  });
});

 

posted @ 2022-10-13 20:31  Zhentiw  阅读(16)  评论(0编辑  收藏  举报