Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sinon: Can't install fake timers twice on the same global object

We have been using useFakeTimers() (sinon v11.x) in many spec files for quite a long time. Recently, we have updated our sinon to 14.x version, now the tests are failing with below error.

TypeError: Can't install fake timers twice on the same global object.

We have tried with createSandbox() also, didn't help.

like image 358
Kamalakannan J Avatar asked Oct 24 '25 17:10

Kamalakannan J


1 Answers

The issue seems like after Sinon 12.x, not restoring the clock in the spec files, injecting it into global scope which throws the aforementioned error.

So the fix is, call clock.restore() in afterAll() or afterEach() based on whether you used beforeAll() or beforeEach().

like image 101
Kamalakannan J Avatar answered Oct 26 '25 07:10

Kamalakannan J