const { TestScheduler } = require("rxjs/testing");
const { map, take, delay } = 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 asynchronous operations", () => {
testScheduler.run((helpers) => {
const { expectObservable } = helpers;
const source$ = from([1, 2, 3]);
const final$ = source$.pipe(delay(5));
const expected = "-- -- -(abc|)";
expectObservable(final$).toBe(expected, { a: 1, b: 2, c: 3 });
const final2$ = source$.pipe(delay(2001));
// 2s: 2 seconds
const expected2 = "2s -(abc|)";
expectObservable(final2$).toBe(expected2, { a: 1, b: 2, c: 3 });
});
});
});
标签:operations,const,marbles,testScheduler,testing,asynchronous,expected From: https://www.cnblogs.com/Answer1215/p/16789601.html