question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug: `resetAllMocks` messes up `runAllTimers` when using `useFakeTimers`

See original GitHub issue

Do 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:open
  • Created 6 years ago
  • Reactions:9
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
SimenBcommented, Feb 6, 2018

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?

1reaction
springupercommented, Jul 17, 2019

it’s a surprise to me that jest. useFakeTimers could be clear by jest.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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

useFakeTimers not working in jest/testing-library
I'm rendering an element that makes use ...
Read more >
usefaketimers beforeall的推薦與評價 ... - 疑難雜症萬事通
usefaketimers beforeall 在bug: `resetAllMocks` messes up `runAllTimers` when using ... 的推薦與評價. In your code you've called the jest.
Read more >
Timer Mocks - Jest
In the following example we enable fake timers by calling jest.useFakeTimers() . This is replacing the original implementation of setTimeout() ...
Read more >
Mocking setTimeout with Jest. | Medium - Marek Rozmus
We need to place the testing code between jest.useFakeTimers() and jest.useRealTimers() . The first one is setting up fake timers and ...
Read more >
Problems with using useFakeTimers('modern') in a create ...
I've written up some notes to hopefully help anyone else who is having the same issue. I was trying to test a component...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found