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

fix: prevent callback from triggering twice when callback throws #681

Merged
merged 1 commit into from
Aug 31, 2021
Merged

fix: prevent callback from triggering twice when callback throws #681

merged 1 commit into from
Aug 31, 2021

Conversation

privatenumber
Copy link
Contributor

closes #542

});

expect(() => jest.runAllTimers()).toThrow('try to trigger catch');
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since wrapAsync uses setImmediate to invoke the callback that throws an error, the error can't be caught.

The only way to catch it seemed to be by stubbing setImmediate, which the jest.useFakerTimers() at the top does. This queues all callbacks until jest.runAllTimers() is invoked, which runs the queued callbacks synchronously to catch the error being thrown.

jest.useFakerTimers() seemed to stub setImmediate for all tests in the file, so I had to put it in a separate file to only influence this specific test.

@reverofevil
Copy link

@streamich Could you please review this?

Copy link
Owner

@streamich streamich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@streamich streamich merged commit 07e8215 into streamich:master Aug 31, 2021
@streamich
Copy link
Owner

🎉 This PR is included in version 3.2.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

Callback was already called.
3 participants