-
Notifications
You must be signed in to change notification settings - Fork 467
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
Unable to mock setTimeout after upgrading to v8.0.0 #992
Comments
I think I have resolved this. The simple solution was to reduce the scope of my |
After spending some time on this I have decided to re-open the issue, as the change introduced in v8.0.0 has limited my ability to test sequences of events in my app that are scheduled using For instance, I have a prompt component to confirm the deletion of an item: Clicking on "delete" opens the prompt, which is faded into view using The only way I can test this functionality is by mocking Can anyone offer any advice here? |
Thanks for the feedback. Closing as a duplicate of #987 since you're facing the same problem: How to mock timers outside of jest? |
I use the following technique to temporarily override the global
setTimeout
to always use a delay of zero. This makes all my transitions instant and my test suite runs nice and fast.I have the following helper function:
And I use it in my tests like this:
It's a nice technique that I think is simple and elegant and has worked well for me for a long time.
After upgrading react-testing-library to v12.0.0, this technique no longer works. All my tests that use my
useZeroTimers
helper are broken.I noticed the following in the release notes for v8.0.0:
I'm not entirely sure what's going on, but I think that as my
useZeroTimers
technique modifies the globalsetTimeout
, it is not compatible with v8.0.0. Is there any workaround that can be suggested for this? If not, could I suggest an option to tellwaitFor
to behave as it did before v8.0.0?The text was updated successfully, but these errors were encountered: