You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
date instanceof Date returns false for dates created before vi.setSystemTime() #9034
After calling vi.setSystemTime(), date instanceof Date appears to return true only if the date was created after the call. If the date was created before vi.setSystemTime(), the result is false.
it('should preserve date instanceof after changing the system time',async()=>{constdateBeforeSettingSystemTime=newDate('2025-11-15T08:00:00.000Z');expect(dateBeforeSettingSystemTime).toBeInstanceOf(Date);// okvi.setSystemTime(dateBeforeSettingSystemTime);constdateAfterSettingSystemTime=newDate();expect(dateAfterSettingSystemTime).toEqual(dateBeforeSettingSystemTime);// system time setexpect(dateAfterSettingSystemTime).toBeInstanceOf(Date);// okexpect(dateBeforeSettingSystemTime).toBeInstanceOf(Date);// fails?});
FAIL example.test.ts > should preserve date instanceof after changing the system time
AssertionError: expected 2025-11-15T08:00:00.000Z to be an instance of MockDate
❯ example.test.ts:13:39
11|
12| expect(dateAfterSettingSystemTime).toBeInstanceOf(Date);
13| expect(dateBeforeSettingSystemTime).toBeInstanceOf(Date);
| ^
14| });
15|
This looks fixed in v5. I ran the repro on a few versions:
4.0.9, 4.0.18, 4.1.0, 4.1.11: fails ("expected ... to be an instance of MockDate")
5.0.0 and 5.0.3: passes
I think #10757 fixed it: setSystemTime without fake timers doesn't use the old MockDate anymore, it uses fake-timers' clock Date, and dates created before the call are still instanceof Date. Also passes with vi.useFakeTimers() first and after vi.useRealTimers().
Activity
Prajwal2246 commentedon Oct 8, 2026
This looks fixed in v5. I ran the repro on a few versions:
I think #10757 fixed it: setSystemTime without fake timers doesn't use the old MockDate anymore, it uses fake-timers' clock Date, and dates created before the call are still
instanceof Date. Also passes withvi.useFakeTimers()first and aftervi.useRealTimers().So this can probably be closed as fixed in 5.0.0.