-
Notifications
You must be signed in to change notification settings - Fork 114
Closed
Labels
Description
- FakeTimers version : @sinonjs/[email protected]
- Environment : nodejs
- Example URL :
- Other libraries you are using: node-opcua, [email protected]
What did you expect to happen?
Date object that have been created before fakeTimer takes actions should still be instanceof Date, as it used to be in previous versions
What actually happens
How to reproduce
npm install sinon@19
import sinon from "sinon";
// defined before useFakeTimers
const minDate = new Date(Date.UTC(1601, 0, 1, 0, 0, 0));
console.log("minDate instanceof Date (before)", minDate instanceof Date);
const clock = sinon.useFakeTimers();
const d = new Date();
console.log("instanceof Date", d instanceof Date);
console.log("minDate instanceof Date (after) : should be true but is : ", minDate instanceof Date);
clock.restore();// without using sinon
import FakeTimers from "@sinonjs/fake-timers";
// emulating what sinonjs is doing:
function createClock(config, globalCtx) {
let FakeTimersCtx = FakeTimers;
if (globalCtx !== null && typeof globalCtx === "object") {
FakeTimersCtx = FakeTimers.withGlobal(globalCtx);
}
const clock = FakeTimersCtx.install(config);
clock.restore = clock.uninstall;
return clock;
}
// defined before useFakeTimers
const minDate = new Date(Date.UTC(1601, 0, 1, 0, 0, 0));
console.log("minDate instanceof Date (before)", minDate instanceof Date);
var clock = createClock();
const d = new Date();
console.log("instanceof Date", d instanceof Date);
console.log("minDate instanceof Date (after) : should be true but is : ", minDate instanceof Date);
clock.restore();