sinonjs / sinon

Test spies, stubs and mocks for JavaScript.

Home Page:https://sinonjs.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

No useRealTimers() or runAllTimers() ?

GeoffreyPlitt opened this issue · comments

I noticed that Sinon's useFakeTimers seems to mirror Jest's almost identically: https://jestjs.io/docs/timer-mocks. However, Sinon doesn't seem to have Jest's useRealTimers() or runAllTimers().

I'm working on a test suite that was already using useFakeTimers, but now has some hanging/deadlocks that only happen when we use fake timers (using real timers, it all succeeds, but takes longer). I wanted to use runAllTimers() to see if it helps.

Any reason Sinon has most of the same functionality as Jest's, but no useRealTimers() or runAllTimers()?

Jest uses @sinonjs/fake-timers under the hood, basically just adding a facade. Just have a peek at the Jest source code to see what fake-timers methods it is calling (I have committed to Jest before, so I know it's very quick to dig into - you can search the code using the Github search interface)

AFAIK, from the link you posted, useRealTimers uninstalls the fake timers. Thus not using any timers. So ... just uninstall the timers? If using fake-timers, just do clock.uninstall();. Pretty sure it's just the instance from fake-timers we return, so you can do the same.

runAllTimers sounds like clock.runAll() or clock.runToLast().