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

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

Merged
merged 1 commit into from Dec 27, 2017

Conversation

@haroldtreen
Copy link
Contributor

@haroldtreen 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
Copy link
Contributor

@3LOK 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
Copy link
Contributor Author

@haroldtreen 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
Copy link
Contributor

@3LOK 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
1 check passed
security/snyk No new issues
Details
@haroldtreen
Copy link
Contributor Author

@haroldtreen haroldtreen commented Dec 27, 2017

Yay! Thanks @3LOK.

What was the failure case?

@3LOK
Copy link
Contributor

@3LOK 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
@tuzmusic
Copy link

@tuzmusic tuzmusic commented May 31, 2019

This doesn't seem to be working for me. The code below is just trying to see this PR's feature working, as per the example at the top of this page.

describe("integration", () => {
  let sagaStore;
  beforeEach(() => {
    sagaStore = new SagaTester({});
    sagaStore.start(authSaga);
  });

  it("returns an error for an invalid username", () => {
    sagaStore.dispatch(login(creds.badUser));
    return sagaStore.waitFor("FAKE_TYPE");
  });
});

And I'm getting the same Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.Error: that this was designed to fix. Am I doing something wrong, or is this an issue?

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

Successfully merging this pull request may close these issues.

None yet

3 participants