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

Cause waitFor to reject if awaited action is never called. #43

Merged
merged 1 commit into from Dec 27, 2017

Conversation

Projects
None yet
2 participants
@haroldtreen
Contributor

haroldtreen commented Dec 16, 2017

Description

Changes the waitFor promise to reject if the provided action is never called.

Example

it('must call SOME_ACTION_THAT_WILL_NEVER_FIRE', () => { 
    const saga = function*() { yield; }
    sagaTester.start(saga);
   return sagaTester.waitFor('SOME_ACTION_THAT_WILL_NEVER_FIRE');
});

Before

Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
  • Not clear what went wrong.
  • Test hangs for 2 seconds before failing.

After

Error: SOME_ACTION_THAT_WILL_NEVER_FIRE was waited for but never called.
  • Communicates that the expected behavior didn't occur.
  • Fails as soon as the saga is exhausted.
@3LOK

This comment has been minimized.

Member

3LOK commented Dec 17, 2017

@haroldtreen hi - Looks good, however I think I'd like a few days to write some tests since I think I have some ideas about use cases when this solution might not work (and I might be wrong of course, just need to be sure). Is that ok?

@haroldtreen

This comment has been minimized.

Contributor

haroldtreen commented Dec 17, 2017

Makes sense! I was also wondering how this might work with

  • multiple sagas
  • a tester that's been reset
  • extra middleware

If you know the cases, I'm also happy to write more tests :).

@3LOK

This comment has been minimized.

Member

3LOK commented Dec 27, 2017

@haroldtreen well, could find a use case to make it fail. merging and keeping my ears open to issues.

@3LOK 3LOK merged commit 80a81ca into wix:master Dec 27, 2017

1 check passed

security/snyk No new issues
Details
@haroldtreen

This comment has been minimized.

Contributor

haroldtreen commented Dec 27, 2017

Yay! Thanks @3LOK.

What was the failure case?

@3LOK

This comment has been minimized.

Member

3LOK commented Dec 27, 2017

@haroldtreen tested all the cases you wrote there. also tried to make redux-saga call the "done" in various cases that won't really be considered "done". Couldn't, so all seems to be good :)

@haroldtreen haroldtreen deleted the haroldtreen:verify-awaited-actions branch Dec 28, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment