{"id":"36b7376686dec3e4","repo":"jestjs/jest","slug":"jest-runalltimersasync-is-not-available-when-u","errorCode":null,"errorMessage":"`jest.runAllTimersAsync()` is not available when using legacy fake timers.","messagePattern":"`jest\\.runAllTimersAsync\\(\\)` 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":389,"sourceCode":"        const fakeTimers = _getFakeTimers();\n\n        if (fakeTimers === this.environment.fakeTimers) {\n          fakeTimers.runAllImmediates();\n        } else {\n          throw new TypeError(\n            '`jest.runAllImmediates()` is only available when using legacy fake timers.',\n          );\n        }\n      },\n      runAllTicks: () => _getFakeTimers().runAllTicks(),\n      runAllTimers: () => _getFakeTimers().runAllTimers(),\n      runAllTimersAsync: async () => {\n        const fakeTimers = _getFakeTimers();\n\n        if (fakeTimers === this.environment.fakeTimersModern) {\n          await fakeTimers.runAllTimersAsync();\n        } else {\n          throw new TypeError(\n            '`jest.runAllTimersAsync()` is not available when using legacy fake timers.',\n          );\n        }\n      },\n      runOnlyPendingTimers: () => _getFakeTimers().runOnlyPendingTimers(),\n      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 => {","sourceCodeStart":371,"sourceCodeEnd":407,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/packages/jest-runtime/src/internals/JestGlobals.ts#L371-L407","documentation":"TypeError thrown by `jest.runAllTimersAsync()` when legacy fake timers are active. The async variant of `runAllTimers` is implemented only on the modern fake timers backend.","triggerScenarios":"Calling `jest.runAllTimersAsync()` after `jest.useFakeTimers({ legacyFakeTimers: true })` or with `fakeTimers.legacyFakeTimers: true` in config.","commonSituations":"Defaulting to legacy timers project-wide while newer tests use the async timer API for async test ergonomics.","solutions":["Switch to modern fake timers: `jest.useFakeTimers()` (default).","If legacy timers are required, use the sync `jest.runAllTimers()` instead of the async variant."],"exampleFix":"// before\njest.useFakeTimers({ legacyFakeTimers: true });\nawait jest.runAllTimersAsync(); // throws\n\n// after\njest.useFakeTimers();\nawait jest.runAllTimersAsync();","handlingStrategy":"validation","validationCode":"// Ensure modern timers before async timer APIs\nfunction useModernTimersThen(fn) {\n  return async () => {\n    jest.useFakeTimers(); // modern\n    await fn();\n  };\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Do not set `fakeTimers.legacyFakeTimers: true` globally.","Use sync `runAllTimers` if a specific test needs legacy timers."],"tags":["fake-timers","legacy","async","config"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}