{"id":"23cb0ebaac7e80dd","repo":"jestjs/jest","slug":"jest-setsystemtime-is-not-available-when-using","errorCode":null,"errorMessage":"`jest.setSystemTime()` is not available when using legacy fake timers.","messagePattern":"`jest\\.setSystemTime\\(\\)` is not available when using legacy fake timers\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/jest-runtime/src/internals/JestGlobals.ts","lineNumber":413,"sourceCode":"      runOnlyPendingTimersAsync: async () => {\n        const fakeTimers = _getFakeTimers();\n\n        if (fakeTimers === this.environment.fakeTimersModern) {\n          await fakeTimers.runOnlyPendingTimersAsync();\n        } else {\n          throw new TypeError(\n            '`jest.runOnlyPendingTimersAsync()` is not available when using legacy fake timers.',\n          );\n        }\n      },\n      setMock: (moduleName, mock) => setMockFactory(moduleName, () => mock),\n      setSystemTime: now => {\n        const fakeTimers = _getFakeTimers();\n\n        if (fakeTimers === this.environment.fakeTimersModern) {\n          fakeTimers.setSystemTime(now);\n        } else {\n          throw new TypeError(\n            '`jest.setSystemTime()` is not available when using legacy fake timers.',\n          );\n        }\n      },\n      setTimeout,\n      setTimerTickMode: (\n        mode:\n          | {mode: 'manual' | 'nextAsync'}\n          | {mode: 'interval'; delta?: number},\n      ) => {\n        const fakeTimers = _getFakeTimers();\n        if (fakeTimers === this.environment.fakeTimersModern) {\n          fakeTimers.setTimerTickMode(mode);\n        } else {\n          throw new TypeError(\n            '`jest.setTimerTickMode()` is not available when using legacy fake timers.',\n          );\n        }","sourceCodeStart":395,"sourceCodeEnd":431,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/packages/jest-runtime/src/internals/JestGlobals.ts#L395-L431","documentation":"TypeError thrown by `jest.setSystemTime()` when legacy fake timers are active. Setting the fake system clock is a modern-fake-timers-only feature; the legacy implementation does not expose `setSystemTime`.","triggerScenarios":"Calling `jest.setSystemTime(now)` while `legacyFakeTimers: true` is set.","commonSituations":"Time-dependent tests (e.g. asserting on `new Date()` output) where the project defaults to legacy timers; time-travel tests for date libraries.","solutions":["Switch to modern fake timers: `jest.useFakeTimers()` (default).","If legacy timers are required, mock `Date` directly with `jest.spyOn(global, 'Date')` or use a library like `mockdate`, though migrating to modern timers is strongly preferred."],"exampleFix":"// before\njest.useFakeTimers({ legacyFakeTimers: true });\njest.setSystemTime(new Date('2025-01-01')); // throws\n\n// after\njest.useFakeTimers();\njest.setSystemTime(new Date('2025-01-01'));","handlingStrategy":"validation","validationCode":"// Modern timers support setSystemTime; legacy does not\njest.useFakeTimers(); // modern\njest.setSystemTime(new Date('2025-01-01'));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use modern fake timers for time-travel tests.","Avoid legacyFakeTimers in config when tests set the system clock."],"tags":["fake-timers","legacy","time","config"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}