-
Notifications
You must be signed in to change notification settings - Fork 272
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
Using Jest mock timers and waitFor together causes tests to timeout #506
Comments
Not sure if I understood your issues correctly. AFAIK when using fake timers you should not use call Please compare how were are using fake timers with It seems that just this change ( Not sure how to fix your failing tests using modern timers. |
@mdjastrzebski thank you for the response. What you said about not awaiting the return of
The phrasing of that always confused me, but I now understand. I'll likely open a PR to improve that piece of documentation. That said, it is still confusing as to why modern timers causes all of the tests to fail in my test case. I'd appreciate any guidance you are able to provide on that issue. Thanks! |
@thymikee maybe you can with modern times here. |
Running |
@thymikee no, running That said, it is curious that "legacy" timers can work, but "modern" timers do not. It is particularly odd that enabling "modern" timers will break a test file if you merely import Is it possible to use "modern" timers and |
Not really sure where the incompatibility comes from. We already had fixed some issues around this topic here: #397, please take a look. In our tests we can safely import |
@thymikee yes, I had reviewed #397 as well in hopes of finding an answer. To reduce the number of variables, I copied the provided tests from RNTL into my test case repository. The new branch ( |
@thymikee I have identified the configuration difference that appears to be the culprit. The RNTL repository babel.config.js does not include The inclusion of At this point, I'm not sure if this is a RNTL issue, Jest issue, or a React Native issue. Do you know why Thanks! |
We don't use Metro babel preset, because we're a Node.js library, not a JSC/Hermes app. You'd need to check on the compiled output to see what's the difference in |
@thymikee makes sense. However, given that this library is intended to be used with a JSC/Hermes app, I would think testing in that environment would be ideal for this library. I'll try to research further. I'm not sure how I'd go about comparing the compiled output Jest holds in-memory. If you have any guidance on that, it'd be appreciated. Thanks. |
Then find "cacheDirectory" and you'll see the transformed output.
We may adjust our Babel config for testing to reflect that, PRs welcome :) |
@thymikee I ran the It appears that when using Without
|
Just hit this problem now as I was migrating our app to RN 0.63. I had a look at how other In version 6 of this library Not sure if this is a known and intended consequence of the deprecation of the previous repo and whatever rewriting took place, but it would be SUPER good to have it in this repo so we don't have to change tonnes of code. However, primarily I think it is unreasonable that using timer mocks in our test would affect the test library code and so I would strongly request that this library ensures it is unaffected by any user-land settings. If the maintainers agree with this direction but don't have the time to do this any time soon then I can take over the implementation. Please let me know. |
Would love to merge a PR fixing that for good 👍 |
Okay it looks like the general approach followed by wait-for-expect to capture the global timer funcs before they get mocked works, but it has highlighted a problem with the 'modern' timer mocks which is caused partially by the Will send a PR tomorrow. |
PR sent, please have a look. |
Describe the bug
Related to #391. Using
jest.useFakeTimers()
in combination withwaitFor
, causes the tests usingwaitFor
to fail due to timeout error:Relying upon
jest.useFakeTimers("modern")
instead causes the above failure for all tests if the file merely importswaitFor
at all, regardless if the given test useswaitFor
or not.Expected behavior
All tests in the reproduction test case should pass.
Steps to Reproduce
yarn install
yarn test
Versions
The text was updated successfully, but these errors were encountered: