sinon.useFakeTimers doesn't work in version 19.0.2, prior 18 version it worked
Ocke-Janssen opened this issue ยท 7 comments
Describe the bug
const clock = sinon.useFakeTimers();
doesn't work any longer in version 19.0.2, in prior 18 version it wokred
To Reproduce
const clock = sinon.useFakeTimers();
clock.tick(1900001);
// here time is not gone by
clock.restore();
cat > test.cjs << EOF
"use strict";
const sinon = require("./lib/sinon.js");
//import * as sinon from "./lib/sinon-esm.js";
const clock = sinon.useFakeTimers();
console.log(Date.now());
clock.tick(1900001);
console.log(Date.now());
clock.restore();
console.log(Date.now());
EOF
node test.cjs
0
1900001
1730154172960
I would say this works fine. Not reproducible.
I tried this code
'use strict';
const sinon = require('sinon');
const timeInPast = new Date(new Date() - 1801000);
console.log(Date.now());
const clock = sinon.useFakeTimers(timeInPast);
console.log(Date.now());
process.nextTick(() => {
console.log('nextTick');
console.log(Date.now());
});
clock.tick(3001);
console.log(Date.now());
// sinon 18 output
1730209204149
1730207403149
1730207406150
nextTick
1730209204153
// sinon 19 output
1730209240516
1730207439516
nextTick
1730207439516
1730207442517
In my case the result in a mysql query not executed.
Ah, see that's why adding a reproduction case is important ๐
Now it makes sense. This is not a bug, but a breaking change which is implied by the semantic version increasing. If you checked out the Sinon change log you'd see the fake timer version change from 11 to 13.
The one that affects you is the change where all timers are faked by default, including nextTick. See our migration guide https://sinonjs.org/guides/migration-guide for what to do.
So the documentation may should be changed ;-)
config.toFake - String[ ] - an array with explicit function names to fake. By default lolex will automatically fake all methods except process.nextTick. You could, however, still fake nextTick by providing it explicitly
Ah, good catch!
I guess you got it from https://sinonjs.org/releases/v19/fake-timers/. I'll update ASAP.