How should `shouldAdvanceTime` work together with `Date`?
sokyrynskyi opened this issue · 1 comments
sokyrynskyi commented
- FakeTimers version : 11.1.0
- Environment : MacOS 13.5.2, NodeJS v18.17.0
- Example URL : -
- Other libraries you are using: -
What did you expect to happen?
Each time new Date()
is called -- the value is advanced according to the config.
What actually happens
The value is always the same.
How to reproduce
it('should advance Date', function() {
const clock = FakeTimers.install({
now: new Date('2022-02-02 22:22:22').getTime(),
shouldAdvanceTime: true,
advanceTimeDelta: 1000,
toFake: ['Date'],
});
console.log('Date1: ', new Date()); // Actual output 'Date1: 2022-02-02T22:22:22.000Z'
console.log('Date2: ', new Date()); // Actual output 'Date2: 2022-02-02T22:22:22.000Z'
clock.uninstall();
});
fatso83 commented
Hi, @sokyrynskyi! AFAIK, there is nothing in the docs that says creating a new date instance should advance time.
tells lolex to increment mocked time automatically based on the real system time shift
To be honest, that would be quite contra-intuitive, as you can create several hundred thousands of date instance per second, so deciding what should the granularity be would be a task upon itself.
You can see examples of how this is being used in the docs.