{"id":"a24a7a42d5ca5e36","repo":"jestjs/jest","slug":"jest-advancetimerstonextframe-is-not-available","errorCode":null,"errorMessage":"`jest.advanceTimersToNextFrame()` is not available when using legacy fake timers.","messagePattern":"`jest\\.advanceTimersToNextFrame\\(\\)` 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":314,"sourceCode":"        _getFakeTimers().advanceTimersByTime(msToRun),\n      advanceTimersByTimeAsync: async msToRun => {\n        const fakeTimers = _getFakeTimers();\n\n        if (fakeTimers === this.environment.fakeTimersModern) {\n          await fakeTimers.advanceTimersByTimeAsync(msToRun);\n        } else {\n          throw new TypeError(\n            '`jest.advanceTimersByTimeAsync()` is not available when using legacy fake timers.',\n          );\n        }\n      },\n      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,","sourceCodeStart":296,"sourceCodeEnd":332,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/packages/jest-runtime/src/internals/JestGlobals.ts#L296-L332","documentation":"TypeError thrown by `jest.advanceTimersToNextFrame()` when legacy fake timers are active. `advanceTimersToNextFrame` is a modern-fake-timers-only API (advances to the next requestAnimationFrame tick) and has no legacy implementation.","triggerScenarios":"Calling `jest.advanceTimersToNextFrame()` while `legacyFakeTimers: true` is set (via config or `useFakeTimers({ legacyFakeTimers: true })`).","commonSituations":"Testing rAF-based code with legacy timers enabled by an old config; team-wide config defaulting to legacy timers while individual tests use modern-only rAF helpers.","solutions":["Use modern fake timers: `jest.useFakeTimers()` (default) and remove `legacyFakeTimers: true`.","If legacy timers are required for other reasons, manually advance time with `jest.advanceTimersByTime(16)` as an approximation for one frame."],"exampleFix":"// before\njest.useFakeTimers({ legacyFakeTimers: true });\njest.advanceTimersToNextFrame(); // throws\n\n// after\njest.useFakeTimers();\njest.advanceTimersToNextFrame();","handlingStrategy":"validation","validationCode":"// Standardize on modern timers in a shared setup helper\nfunction withModernFakeTimers(fn) {\n  return () => {\n    jest.useFakeTimers(); // modern\n    fn();\n  };\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Avoid `legacyFakeTimers: true` in jest.config — modern timers support rAF.","Wrap rAF-based timer helpers so they only run under modern timers."],"tags":["fake-timers","legacy","raf","config"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}