{"id":"c537d7c1867ccbf8","repo":"jestjs/jest","slug":"jest-runallimmediates-is-only-available-when-u","errorCode":null,"errorMessage":"`jest.runAllImmediates()` is only available when using legacy fake timers.","messagePattern":"`jest\\.runAllImmediates\\(\\)` is only available when using legacy fake timers\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/jest-runtime/src/internals/JestGlobals.ts","lineNumber":376,"sourceCode":"      isolateModulesAsync,\n      mock,\n      mocked,\n      now: () => _getFakeTimers().now(),\n      onGenerateMock,\n      replaceProperty,\n      requireActual: moduleName => this.requireActualBridge(from, moduleName),\n      requireMock: moduleName => this.requireMockBridge(from, moduleName),\n      resetAllMocks,\n      resetModules,\n      restoreAllMocks,\n      retryTimes,\n      runAllImmediates: () => {\n        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(),","sourceCodeStart":358,"sourceCodeEnd":394,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/packages/jest-runtime/src/internals/JestGlobals.ts#L358-L394","documentation":"TypeError thrown by `jest.runAllImmediates()` when modern fake timers are active. `runAllImmediates` flushes `setImmediate` queues and exists ONLY on the legacy fake timers implementation — the inverse of the other timer errors.","triggerScenarios":"Calling `jest.runAllImmediates()` while modern fake timers are active (the default). The modern backend does not implement `setImmediate` flushing.","commonSituations":"Using the default modern timers in a test copied from an older Jest codebase that relied on `runAllImmediates`; testing code that uses `setImmediate` and expecting the legacy flush behavior.","solutions":["Switch to legacy fake timers: `jest.useFakeTimers({ legacyFakeTimers: true })` — but note legacy timers are deprecated.","Preferably, replace `setImmediate`-based code with `queueMicrotask`/`Promise.resolve()` or use `jest.runAllTicks()` to flush microtasks under modern timers.","If you specifically need to flush macrotasks, await a real `new Promise(r => setImmediate(r))` with real timers."],"exampleFix":"// before\njest.useFakeTimers(); // modern\njest.runAllImmediates(); // throws\n\n// after (option 1: legacy)\njest.useFakeTimers({ legacyFakeTimers: true });\njest.runAllImmediates();\n\n// after (option 2: modern, flush microtasks instead)\njest.useFakeTimers();\njest.runAllTicks();","handlingStrategy":"validation","validationCode":"// runAllImmediates needs legacy timers; modern tests should flush microtasks\nfunction flushImmediateQueue() {\n  // legacy path:\n  // jest.useFakeTimers({ legacyFakeTimers: true }); jest.runAllImmediates();\n  // modern equivalent:\n  jest.runAllTicks();\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer `jest.runAllTicks()` for microtask flushing under modern timers.","Refactor `setImmediate`-based code to promises/queueMicrotask to avoid this API entirely.","If you must use runAllImmediates, explicitly opt into legacy timers in that test only."],"tags":["fake-timers","legacy","setimmediate"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}