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.

Sinon fails to uninstall clock when using jest.fakeTimers()

See original GitHub issue

I am using both Sinon clock and jest.useFakeTimers for legacy reasons, and I am getting an error while trying to uninstall sinon clock: TypeError: _global.setInterval is not a function after enabling jest.useFakeTimers() during some test. I know that it’s a bit fucked up to use both sinon and jest.useFakeTimers, but anyways I think that sinon should handle this situation gracefully.

  • FakeTimers version : 8.1.0
  • Environment : node
  • Example URL :
  • Other libraries you are using: React native testing library, jest

What did you expect to happen? Sinon should be able to uninstall clock even after using jest.fakeTimers What actually happens Sinon throws exception when trying to uninstall clock after using jest.fakeTimers How to reproduce

  1. install sinon clock:
  clock = FakeTimers.install({
    shouldAdvanceTime: true,
  });
  1. use jest.fakeTimers()
  2. try to uninstall clock.
  3. TypeError: _global.setInterval is not a function

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
SimenBcommented, Dec 25, 2021

26 (by default) uses its own implementation and the one using Lolex is opt-in via jest.useFakeTimere('modern'). In v27 “modern” is the default. Might also be a mismatch in version of Lolex of course

2reactions
SimenBcommented, Dec 22, 2021

Note that Jest ships with @sinonjs/fake-timers if you use “modern” fake timers (default in v27), and mixing them is not supported. You should use one or the other.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Timeout when using jest "useFakeTimers" functionality #2200
When mocking timers in jest I would expect mocks to pass properly as those (to ... Remove fake timers and the test case...
Read more >
Timer Mocks - Jest
In the following example we enable fake timers by calling jest.useFakeTimers() . This is replacing the original implementation of ...
Read more >
Sinon fake timers and syncing ticks with unpredictable timers ...
The test calls foo and then advances the clock by 20 seconds to trigger the timer, but most of the time it will...
Read more >
When using Sinon's useFakeTimers, access the real time and ...
I'm using Sinon's useFakeTimers to test a time-dependent module. When in "fake time" mode, I need to use the real setTimeout, meaning that...
Read more >
Using Fake Timers | Testing Library
When using fake timers in your tests, all of the code inside your ... Running all pending timers and switching to real timers...
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