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

  1. Switch to modern fake timers: `jest.useFakeTimers()` (default).
  2. 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

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


AI-assisted analysis of jestjs/jest@f49721c78e (2026-08-03). Data as JSON: /data/errors/f1c48f18e2b9219d.json. Report an issue: GitHub.