How to use the rxjs-marbles/jest.fakeSchedulers function in rxjs-marbles

To help you get started, we’ve selected a few rxjs-marbles examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github trivago / melody / packages / melody-streams / __tests__ / componentSpec.js View on Github external
const error = new Error('oops!');
        const MyComponent = createComponent(
            () => concat(of(7), throwError(error)),
            template
        );
        /* eslint-disable no-console */
        const temp = console.error;
        console.error = jest.fn();
        render(root, MyComponent);
        expect(console.error).toHaveBeenCalledWith('Error: ', error);
        console.error = temp;
        /* eslint-enable no-console */
    });
    it(
        'should not emit a warning message after if component emits state before 500ms if not state updates',
        fakeSchedulers(advance => {
            jest.useFakeTimers();
            const root = document.createElement('div');
            const MyComponent = createComponent(({ props }) => props, template);
            render(root, MyComponent, { value: 'foo' });
            /* eslint-disable no-console */
            const temp = console.warn;
            console.warn = jest.fn();
            advance(500);
            expect(console.warn).not.toHaveBeenCalledWith(
                'Warning: Your Component did not emit any state updates for at least 500ms.'
            );
            console.warn = temp;
            /* eslint-enable no-console */
        })
    );
    it('should unmount replaced components', () => {
github cartant / rxjs-marbles / examples / jest / fake-spec.ts View on Github external
it(
    "should support a timer",
    fakeSchedulers(advance => {
      let received: number | undefined;
      timer(100).subscribe(value => (received = value));
      advance(50);
      expect(received).not.toBeDefined();
      advance(50);
      expect(received).toBe(0);
    })
  );

  it(
    "should support delay",
    fakeSchedulers(advance => {
      let received: number | undefined;
      of(1)
        .pipe(delay(100))
        .subscribe(value => (received = value));
      advance(50);
      expect(received).not.toBeDefined();
      advance(50);
      expect(received).toBe(1);
    })
  );
});