Tests that touch time use a fake clock
A test that calls Date.now() passes at 2pm and fails at midnight, or on the last day of February. Inject the clock, or freeze it.
vi.useFakeTimers();
vi.setSystemTime(new Date("2026-02-28T23:59:00Z"));
expect(isExpired(token)).toBe(false);
vi.advanceTimersByTime(120_000);
expect(isExpired(token)).toBe(true);Same for setTimeout and intervals: advancing a fake clock beats sleeping in a test.
testing