jestjs/jest · error · TypeError
`jest.runOnlyPendingTimersAsync()` is not available when usi
Error message
`jest.runOnlyPendingTimersAsync()` is not available when using legacy fake timers.
What it means
TypeError thrown by `jest.runOnlyPendingTimersAsync()` when legacy fake timers are active. The async variant is a modern-fake-timers-only API.
Source
Thrown at packages/jest-runtime/src/internals/JestGlobals.ts:401
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 => {
const fakeTimers = _getFakeTimers();
if (fakeTimers === this.environment.fakeTimersModern) {
fakeTimers.setSystemTime(now);
} else {
throw new TypeError(
'`jest.setSystemTime()` is not available when using legacy fake timers.',
);
}
},
setTimeout,
setTimerTickMode: (View on GitHub (pinned to f49721c78e)
Solutions
- Switch to modern fake timers: `jest.useFakeTimers()` (default).
- If you must keep legacy timers, use the sync `jest.runOnlyPendingTimers()` instead.
Example fix
// before
jest.useFakeTimers({ legacyFakeTimers: true });
await jest.runOnlyPendingTimersAsync(); // throws
// after
jest.useFakeTimers();
await jest.runOnlyPendingTimersAsync(); Defensive patterns
Strategy: validation
Validate before calling
// Gate async timer APIs on modern timers
function modernOnly(fn) {
// ensure config does not set legacyFakeTimers: true
return fn();
} Prevention
- Default to modern fake timers project-wide.
- Use sync `runOnlyPendingTimers` for legacy-timer tests.
When it happens
Trigger: Calling `jest.runOnlyPendingTimersAsync()` while `legacyFakeTimers: true` is in effect.
Common situations: Project-wide legacy timer config combined with tests using the async pending-timer flush.
Related errors
- `jest.advanceTimersByTimeAsync()` is not available when usin
- `jest.advanceTimersToNextTimerAsync()` is not available when
- `jest.runAllTimersAsync()` is not available when using legac
- `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/3a3a55c08284c251.json.
Report an issue: GitHub.