jestjs/jest · error · TypeError
`jest.runAllTimersAsync()` is not available when using legac
Error message
`jest.runAllTimersAsync()` is not available when using legacy fake timers.
What it means
TypeError thrown by `jest.runAllTimersAsync()` when legacy fake timers are active. The async variant of `runAllTimers` is implemented only on the modern fake timers backend.
Source
Thrown at packages/jest-runtime/src/internals/JestGlobals.ts:389
const fakeTimers = _getFakeTimers();
if (fakeTimers === this.environment.fakeTimers) {
fakeTimers.runAllImmediates();
} else {
throw new TypeError(
'`jest.runAllImmediates()` is only available when using legacy fake timers.',
);
}
},
runAllTicks: () => _getFakeTimers().runAllTicks(),
runAllTimers: () => _getFakeTimers().runAllTimers(),
runAllTimersAsync: async () => {
const fakeTimers = _getFakeTimers();
if (fakeTimers === this.environment.fakeTimersModern) {
await fakeTimers.runAllTimersAsync();
} else {
throw new TypeError(
'`jest.runAllTimersAsync()` is not available when using legacy fake timers.',
);
}
},
runOnlyPendingTimers: () => _getFakeTimers().runOnlyPendingTimers(),
runOnlyPendingTimersAsync: async () => {
const fakeTimers = _getFakeTimers();
if (fakeTimers === this.environment.fakeTimersModern) {
await fakeTimers.runOnlyPendingTimersAsync();
} else {
throw new TypeError(
'`jest.runOnlyPendingTimersAsync()` is not available when using legacy fake timers.',
);
}
},
setMock: (moduleName, mock) => setMockFactory(moduleName, () => mock),
setSystemTime: now => {View on GitHub (pinned to f49721c78e)
Solutions
- Switch to modern fake timers: `jest.useFakeTimers()` (default).
- If legacy timers are required, use the sync `jest.runAllTimers()` instead of the async variant.
Example fix
// before
jest.useFakeTimers({ legacyFakeTimers: true });
await jest.runAllTimersAsync(); // throws
// after
jest.useFakeTimers();
await jest.runAllTimersAsync(); Defensive patterns
Strategy: validation
Validate before calling
// Ensure modern timers before async timer APIs
function useModernTimersThen(fn) {
return async () => {
jest.useFakeTimers(); // modern
await fn();
};
} Prevention
- Do not set `fakeTimers.legacyFakeTimers: true` globally.
- Use sync `runAllTimers` if a specific test needs legacy timers.
When it happens
Trigger: Calling `jest.runAllTimersAsync()` after `jest.useFakeTimers({ legacyFakeTimers: true })` or with `fakeTimers.legacyFakeTimers: true` in config.
Common situations: Defaulting to legacy timers project-wide while newer tests use the async timer API for async test ergonomics.
Related errors
- `jest.advanceTimersByTimeAsync()` is not available when usin
- `jest.advanceTimersToNextTimerAsync()` is not available when
- `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/36b7376686dec3e4.json.
Report an issue: GitHub.