Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setSystemTime is not available when not using modern timers #11660

Closed
jasonwilliams opened this issue Jul 13, 2021 · 3 comments · Fixed by #11946
Closed

setSystemTime is not available when not using modern timers #11660

jasonwilliams opened this issue Jul 13, 2021 · 3 comments · Fixed by #11946

Comments

@jasonwilliams
Copy link

jasonwilliams commented Jul 13, 2021

🐛 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
@simon-paris
Copy link

simon-paris commented Jul 14, 2021

Oh hey, I was just here to report something similar.

It's a bug in jest, the trigger is having mismatched versions of jest-* libraries. Downgrade jest and babel-jest to 27.0.3.

I've created another issue with a little more detail on why this happens. #11662

@jasonwilliams
Copy link
Author

@simon-paris yes you're right i was using a yarn workspace and the bug went away when all of my packages were on the same version of Jest

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants