Wraps Jest's built-in modern fake-timers (built on @sinonjs/fake-timers since Jest 27): jest.useFakeTimers(), jest.setSystemTime(), jest.advanceTimersByTime(), jest.runAllTimers(), and jest.useRealTimers() for selective restoration. Use when testing JS/TS code in Jest where setTimeout / setInterval / Date / Date.now need deterministic control.
80
100%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
View guide
Passed
No findings from the security scan
Selective faking, DST/timezone tests, and fake-timer + mocked
fetch interplay extracted from the core skill. Enable / advance
/ run-all usage stays in SKILL.md.
jest.useFakeTimers({
doNotFake: ['nextTick', 'queueMicrotask'],
now: new Date('2026-05-20T14:30:00Z').getTime(),
});Set the runtime zone before enabling fake timers, then set system time to the UTC instant of the transition.
beforeAll(() => {
process.env.TZ = 'America/New_York';
jest.useFakeTimers();
});
test('spring-forward behaviour', () => {
jest.setSystemTime(new Date('2026-03-08T06:30:00Z')); // 02:30 EDT - invalid local
expect(new Date().toString()).toMatch(/03:30/); // Browser/Node normalises
});If fetch is mocked separately, ensure the mock awaits a faked
timer too:
test('debounce + fetch', async () => {
global.fetch = jest.fn().mockResolvedValue({ json: () => ({ ok: true }) });
myDebouncedFetch();
await jest.advanceTimersByTimeAsync(300);
expect(fetch).toHaveBeenCalled();
});