jestjs/jest · error · TypeError
`jest.advanceTimersToNextTimerAsync()` is not available when
Error message
`jest.advanceTimersToNextTimerAsync()` is not available when using legacy fake timers.
What it means
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.
Source
Thrown at packages/jest-runtime/src/internals/JestGlobals.ts:326
advanceTimersToNextFrame: () => {
const fakeTimers = _getFakeTimers();
if (fakeTimers === this.environment.fakeTimersModern) {
return fakeTimers.advanceTimersToNextFrame();
}
throw new TypeError(
'`jest.advanceTimersToNextFrame()` is not available when using legacy fake timers.',
);
},
advanceTimersToNextTimer: steps =>
_getFakeTimers().advanceTimersToNextTimer(steps),
advanceTimersToNextTimerAsync: async steps => {
const fakeTimers = _getFakeTimers();
if (fakeTimers === this.environment.fakeTimersModern) {
await fakeTimers.advanceTimersToNextTimerAsync(steps);
} else {
throw new TypeError(
'`jest.advanceTimersToNextTimerAsync()` is not available when using legacy fake timers.',
);
}
},
autoMockOff: disableAutomock,
autoMockOn: enableAutomock,
clearAllMocks,
clearAllTimers: () => _getFakeTimers().clearAllTimers(),
createMockFromModule: moduleName => this.generateMock(from, moduleName),
deepUnmock,
disableAutomock,
doMock: mock,
dontMock: unmock,
enableAutomock,
fn,
getRealSystemTime: () => {
const fakeTimers = _getFakeTimers();
View on GitHub (pinned to f49721c78e)
Solutions
- Switch to modern fake timers: `jest.useFakeTimers()` (default).
- If staying on legacy, use the sync `jest.advanceTimersToNextTimer()` instead.
Example fix
// before
jest.useFakeTimers({ legacyFakeTimers: true });
await jest.advanceTimersToNextTimerAsync(); // throws
// after
jest.useFakeTimers();
await jest.advanceTimersToNextTimerAsync(); Defensive patterns
Strategy: validation
Validate before calling
// Prefer modern timers; gate async timer calls behind a check
function safeAdvanceToNextTimerAsync() {
// modern timers is the default; ensure legacyFakeTimers is not set in config
return jest.advanceTimersToNextTimerAsync();
} Prevention
- Do not enable legacy fake timers in jest.config.
- Use the sync `advanceTimersToNextTimer` if you must run under legacy timers.
When it happens
Trigger: Calling `jest.advanceTimersToNextTimerAsync()` after enabling legacy fake timers (`legacyFakeTimers: true`).
Common situations: Old project config with `fakeTimers: { legacyFakeTimers: true }`; tests copied from a modern-timers codebase into a legacy-timers suite.
Related errors
- `jest.advanceTimersByTimeAsync()` is not available when usin
- `jest.runAllTimersAsync()` is not available when using legac
- `jest.runOnlyPendingTimersAsync()` is not available when usi
- `jest.advanceTimersToNextFrame()` is not available when usin
- `jest.getRealSystemTime()` is not available when using legac
AI-assisted analysis of jestjs/jest@f49721c78e (2026-08-03).
Data as JSON: /data/errors/f1c48f18e2b9219d.json.
Report an issue: GitHub.