{"id":"3a3a55c08284c251","repo":"jestjs/jest","slug":"jest-runonlypendingtimersasync-is-not-availabl","errorCode":null,"errorMessage":"`jest.runOnlyPendingTimersAsync()` is not available when using legacy fake timers.","messagePattern":"`jest\\.runOnlyPendingTimersAsync\\(\\)` 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":401,"sourceCode":"      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 => {\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: (","sourceCodeStart":383,"sourceCodeEnd":419,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/packages/jest-runtime/src/internals/JestGlobals.ts#L383-L419","documentation":"TypeError thrown by `jest.runOnlyPendingTimersAsync()` when legacy fake timers are active. The async variant is a modern-fake-timers-only API.","triggerScenarios":"Calling `jest.runOnlyPendingTimersAsync()` while `legacyFakeTimers: true` is in effect.","commonSituations":"Project-wide legacy timer config combined with tests using the async pending-timer flush.","solutions":["Switch to modern fake timers: `jest.useFakeTimers()` (default).","If you must keep legacy timers, use the sync `jest.runOnlyPendingTimers()` instead."],"exampleFix":"// before\njest.useFakeTimers({ legacyFakeTimers: true });\nawait jest.runOnlyPendingTimersAsync(); // throws\n\n// after\njest.useFakeTimers();\nawait jest.runOnlyPendingTimersAsync();","handlingStrategy":"validation","validationCode":"// Gate async timer APIs on modern timers\nfunction modernOnly(fn) {\n  // ensure config does not set legacyFakeTimers: true\n  return fn();\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default to modern fake timers project-wide.","Use sync `runOnlyPendingTimers` for legacy-timer tests."],"tags":["fake-timers","legacy","async","config"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}