-
Notifications
You must be signed in to change notification settings - Fork 273
RNTL accidentally triggers jest.useFakeTimers
#886
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
Comments
jest.useFakeTimers
@Niryo can you check if the issue persists with current version of RNTL with Jest 29? |
Yea, I'll check it later this week |
@mdjastrzebski yep, it's still an issue |
@Niryo thanks for checking it. BTW Jest recently (v27 or v28) added more features to its fake timers implementation. Does sinon-fake-timers still has some features that Jest does not? |
@mdjastrzebski jest still exposes only a subset of sinon's options |
@Niryo The recommended workaround for your specific use case is to you Patch Package locally in order to tweak RNTL behavior to your needs. You use cases seems quite rare, and relevant only for advanced users that need more fake timer features. Such users should be able to make relevant changes using patch package. I am wary of altering the default behavior for majority of the users. We source our Jest timer detection code from Dom Testing Library, so it seems that RTL/DTL would also have the same behavior. Alternative option of introducing some new API for controlling fake timer behavior seems to add too much complexity for primary use cases. If you feel that you can come up with simple API that would solve your problem without affecting other users by default and without complicating our API too much feel free to submit a PR for such change. |
I agree that it's a rare use case. what about introducing an env param? you already have this |
Sounds like a reasonable solution that would not complicate the API surface for regular users. @Niryo would you be able to submit a PR for that? |
yep, i'll do it |
Describe the bug
I am using sinon-fake-timers together with jest, because jest's exposes only minimal part of sinon timers and I need more advanced capabilities. The thing is that React native testing library mistakenly thinks that I am using "jest.useFakeTimers", because of this check:
The first statement is true because I am using sinon fake timers, and the second is true because I am using jest, so it assumes that I am using
jest.useFakeTimers
, and it automatically turn it on for me here:This results in both custom sinon timer and jest's fake timers being installed, and it causes issues in my tests.
Expected behavior
jest.useFakeTimers
should not be called if the user didn't call it explicitly.Steps to Reproduce
use jest 27 and sinon-fake-timers
Versions
npmPackages:
@testing-library/react-native: ^9.0.0 => 9.0.0
react-test-renderer: ^17.0.2 => 17.0.2
The text was updated successfully, but these errors were encountered: