jestjs/jest · error · TypeError

`jest.getRealSystemTime()` is not available when using legac

Error message

`jest.getRealSystemTime()` is not available when using legacy fake timers.

What it means

TypeError thrown by `jest.getRealSystemTime()` when legacy fake timers are active. Reading the real system clock while faking time is a modern-fake-timers-only feature; the legacy implementation does not expose it.

Source

Thrown at packages/jest-runtime/src/internals/JestGlobals.ts:348

      },
      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();

        if (fakeTimers === this.environment.fakeTimersModern) {
          return fakeTimers.getRealSystemTime();
        } else {
          throw new TypeError(
            '`jest.getRealSystemTime()` is not available when using legacy fake timers.',
          );
        }
      },
      getSeed: () => this.globalConfig.seed,
      getTimerCount: () => _getFakeTimers().getTimerCount(),
      isEnvironmentTornDown: () => this.testState.isTornDown(),
      isMockFunction: this.moduleMocker.isMockFunction,
      isolateModules,
      isolateModulesAsync,
      mock,
      mocked,
      now: () => _getFakeTimers().now(),
      onGenerateMock,
      replaceProperty,
      requireActual: moduleName => this.requireActualBridge(from, moduleName),
      requireMock: moduleName => this.requireMockBridge(from, moduleName),
      resetAllMocks,

View on GitHub (pinned to f49721c78e)

Solutions

  1. Switch to modern fake timers: `jest.useFakeTimers()` (default).
  2. If you must keep legacy timers, capture `Date.now()` or `performance.now()` before `useFakeTimers` and reuse that reference.

Example fix

// before
jest.useFakeTimers({ legacyFakeTimers: true });
const real = jest.getRealSystemTime(); // throws

// after
jest.useFakeTimers();
const real = jest.getRealSystemTime();
Defensive patterns

Strategy: validation

Validate before calling

// Capture real time before faking if you may run under legacy timers
const realStart = Date.now();
jest.useFakeTimers(); // modern; then jest.getRealSystemTime() is available

Prevention

When it happens

Trigger: Calling `jest.getRealSystemTime()` with `legacyFakeTimers: true` set in config or via `useFakeTimers`.

Common situations: Logging or seeding real timestamps inside a fake-timer test where the project defaulted to legacy timers; profiling code that reads real time between fake ticks.

Related errors


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