Skip to content

setSystemTime is not available when not using modern timers #11660

@jasonwilliams

Description

@jasonwilliams

🐛 Bug Report

Since updating to jest v27 i get setSystemTime is not available when not using modern timers. I've always explicitly set timers to modern (which you can see below), but that doesn't seem to work.

  • ts-jest: 27.0.3
  • jest: 27.0.6
  • babel-jest: 27.0.6

My config also includes:

    timers: 'modern',
    TypeError: setSystemTime is not available when not using modern timers

      4 |     beforeAll(() => {
      5 |         jest.useFakeTimers('modern');
    > 6 |         jest.setSystemTime(new Date('2020-01-01T00:00:00.000Z'));
        |              ^
      7 |     });
      8 |
      9 |     afterAll(() => {

It fails here:
https://github.com/facebook/jest/blob/59f42d86756fcc3c9caf0c8a5cf1b13324941d4e/packages/jest-runtime/src/index.ts#L1776-L1780

But when i break on that line (1776) it does look like fakeTimers are the modern variant.

Also setSystemTime is not available when not using modern timers is a double negative, a better error message could be neccesary

To Reproduce

Steps to reproduce the behavior:

Expected behavior

For it to not moan

Link to repl or repo (highly encouraged)

envinfo

  System:
    OS: macOS 10.15.7
    CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
  Binaries:
    Node: 16.3.0 - ~/.nvm/versions/node/v16.3.0/bin/node
    Yarn: 2.4.2 - /usr/local/bin/yarn
    npm: 7.15.1 - ~/.nvm/versions/node/v16.3.0/bin/npm
  npmPackages:
    jest: ^27.0.6 => 27.0.6

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions