Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toSatisfyOnFlush does not work with delays? #394

Open
schmkr opened this issue Oct 15, 2021 · 0 comments
Open

toSatisfyOnFlush does not work with delays? #394

schmkr opened this issue Oct 15, 2021 · 0 comments

Comments

@schmkr
Copy link

schmkr commented Oct 15, 2021

Hi,

Today I learned about this new helper function toSatisfyOnFlush which removes the need to run tests in a testScheduler.run() callback, manually flushing an observable after subscribing.

While replacing those testScheduler.run() tests with expect(stream).toSatisfyOnFlush(() => {}), I came across a use case where the use of the delay() operator does not seem to get flushed with that helper function.

Stream:

// NgRx Effect:
readonly pongReceived$ = createEffect(
  () =>
    this.actions$.pipe(
      ofType(actions.pongReceived),
      delay(60000), // one minute
      tap(() => this.someService.sendPing()),
    ),
  { dispatch: false },
);

With TestScheduler.run, this works and the spied method has been called

it('should call someService.sendPing', () => {
  testScheduler.run(({ hot, flush }) => {
    const action = actions.pongReceived();
    actions$ = hot('-a', { a: action });
    const spy = jest
      .spyOn(someService, 'sendPing')
      .mockImplementationOnce(() => undefined);

    effects.pongReceived$.subscribe();
    flush();

    expect(spy).toHaveBeenCalledTimes(1);
  });
});

With toSatisfyOnFlush this does not seem to work:

it('should call someService.sendPing', () => {
  testScheduler.run(({ hot, flush }) => {
    const action = actions.pongMessageReceived();
    actions$ = hot('-a', { a: action });
    const spy = jest
      .spyOn(someService, 'sendPing')
      .mockImplementationOnce(() => undefined);

  expect(effects.pongReceived$).toSatisfyOnFlush(() => {
    expect(spy).toHaveBeenCalledTimes(1);
  });
});

Is there a particular reason, time related operators aren't flushed? Based on the name of the helper function, I would have assumed it would. Is it related to the time progression syntax not being supported (#117)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant