@datakitchen/rxjs-marbles
TypeScript icon, indicating that this package has built-in type declarations

17.0.0 • Public • Published

@datakitchen/rxjs-marbles

Wrapper around rxjs own TestScheduler used to simplify and streamline marble testing.

Install

With the package manager of your choice install

@datakitchen/rxjs-marbles

TestScheduler

expect(expected).toEqual(actual) this the current comparator used so this package can only be used with testing frameworks and support this syntax.

To instantiate a new TestScheduler

let testScheduler: TestScheduler;

beforeEach(() => {
    testScheduler = new TestScheduler();
});

testScheduler extends rxjs' own TestScheduler so expectObservable can be used as usual

it('.toBe', () => {
    const source$ = new BehaviorSubject(1);
    testScheduler.expectObservable(source$).toBe('(a|)', {a: 1});
});

it('.toEqual', () => {
    const source$ = new BehaviorSubject(1);
    testScheduler.expectObservable(source$).toEqual(of(1));
});

Both the above pass. Also if anything need to happen when asserting an observable .run method can be used as in

it('.run', () => {
    testScheduler.run(({cold, expectObservable}) => {
        const cold$ = cold('---a');
        expectObservable(cold$).toBe('---a');
    });
});

This package add a new method expect$ with few differences with expectObservable

  • .run works exactly the same
  • .toEqual is stricter and will fail the above test but pass the following
it('.toEqual', () => {
    const source$ = new BehaviorSubject(1);
    const expected$ = new BehaviorSubject(1);
    testScheduler.expect$(source$).toEqual(expected$);
});
  • .toContain can check whether a stream contains a given value. I.e.:
it('.toContain', () => {
    testScheduler.expect$(from([ 1, 2, 3 ])).toContain(2);
});

Readme

Keywords

Package Sidebar

Install

npm i @datakitchen/rxjs-marbles

Weekly Downloads

9

Version

17.0.0

License

MIT

Unpacked Size

14.4 kB

Total Files

9

Last publish

Collaborators

  • datakitchen_admin