{"id":"f1c48f18e2b9219d","repo":"jestjs/jest","slug":"jest-advancetimerstonexttimerasync-is-not-avai","errorCode":null,"errorMessage":"`jest.advanceTimersToNextTimerAsync()` is not available when using legacy fake timers.","messagePattern":"`jest\\.advanceTimersToNextTimerAsync\\(\\)` 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":326,"sourceCode":"      advanceTimersToNextFrame: () => {\n        const fakeTimers = _getFakeTimers();\n\n        if (fakeTimers === this.environment.fakeTimersModern) {\n          return fakeTimers.advanceTimersToNextFrame();\n        }\n        throw new TypeError(\n          '`jest.advanceTimersToNextFrame()` is not available when using legacy fake timers.',\n        );\n      },\n      advanceTimersToNextTimer: steps =>\n        _getFakeTimers().advanceTimersToNextTimer(steps),\n      advanceTimersToNextTimerAsync: async steps => {\n        const fakeTimers = _getFakeTimers();\n\n        if (fakeTimers === this.environment.fakeTimersModern) {\n          await fakeTimers.advanceTimersToNextTimerAsync(steps);\n        } else {\n          throw new TypeError(\n            '`jest.advanceTimersToNextTimerAsync()` is not available when using legacy fake timers.',\n          );\n        }\n      },\n      autoMockOff: disableAutomock,\n      autoMockOn: enableAutomock,\n      clearAllMocks,\n      clearAllTimers: () => _getFakeTimers().clearAllTimers(),\n      createMockFromModule: moduleName => this.generateMock(from, moduleName),\n      deepUnmock,\n      disableAutomock,\n      doMock: mock,\n      dontMock: unmock,\n      enableAutomock,\n      fn,\n      getRealSystemTime: () => {\n        const fakeTimers = _getFakeTimers();\n","sourceCodeStart":308,"sourceCodeEnd":344,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/packages/jest-runtime/src/internals/JestGlobals.ts#L308-L344","documentation":"TypeError thrown by `jest.advanceTimersToNextTimerAsync()` when legacy fake timers are active. Like the other async timer methods, this one is implemented only on the modern fake timers backend.","triggerScenarios":"Calling `jest.advanceTimersToNextTimerAsync()` after enabling legacy fake timers (`legacyFakeTimers: true`).","commonSituations":"Old project config with `fakeTimers: { legacyFakeTimers: true }`; tests copied from a modern-timers codebase into a legacy-timers suite.","solutions":["Switch to modern fake timers: `jest.useFakeTimers()` (default).","If staying on legacy, use the sync `jest.advanceTimersToNextTimer()` instead."],"exampleFix":"// before\njest.useFakeTimers({ legacyFakeTimers: true });\nawait jest.advanceTimersToNextTimerAsync(); // throws\n\n// after\njest.useFakeTimers();\nawait jest.advanceTimersToNextTimerAsync();","handlingStrategy":"validation","validationCode":"// Prefer modern timers; gate async timer calls behind a check\nfunction safeAdvanceToNextTimerAsync() {\n  // modern timers is the default; ensure legacyFakeTimers is not set in config\n  return jest.advanceTimersToNextTimerAsync();\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Do not enable legacy fake timers in jest.config.","Use the sync `advanceTimersToNextTimer` if you must run under legacy timers."],"tags":["fake-timers","legacy","async","config"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}