bug: `resetAllMocks` messes up `runAllTimers` when using `useFakeTimers`
See original GitHub issueDo you want to request a feature or report a bug? Bug
What is the current behavior?
When using useFakeTimers
, running resetAllMocks
messes up runAllTimers
in the second test (it does not advance the timer) and the test times out (fails).
If the current behavior is a bug, please provide the steps to reproduce and
either a repl.it demo through https://repl.it/languages/jest or a minimal
repository on GitHub that we can yarn install
and yarn test
.
https://repl.it/repls/CarelessNormalAssassinbug
What is the expected behavior?
resetAllMocks
should indeed reset the calls
instances of the setTimeout
mock, but runAllTimers
should still work as expected and complete the setTimeout
Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system. Jest v22.1.4 Node v9.3.0 Yarn v1.3.2 Mac OS X 10.12.6
Issue Analytics
- State:
- Created 6 years ago
- Reactions:9
- Comments:12 (3 by maintainers)
Top GitHub Comments
I was not aware that we made
setTimeout
and friends into spies - I’m not sure how that will work once we start using Lolex (#5165).So for now I’d say we should document the current behaviour. Thoughts @cpojer @thymikee?
it’s a surprise to me that
jest. useFakeTimers
could be clear byjest.resetAllMocks
, no document for it and I spent one hour to figure out the root cause. If this is the rule, could you update related documents as well?