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

TypeError Since Node 19 #463

Closed
charlieyeng opened this issue Apr 25, 2023 · 4 comments
Closed

TypeError Since Node 19 #463

charlieyeng opened this issue Apr 25, 2023 · 4 comments

Comments

@charlieyeng
Copy link

We understand you have a problem and are in a hurry, but please provide us with some info to make it much more likely for your issue to be understood, worked on and resolved quickly.

  • FakeTimers version : 10.0.2
  • Environment : macOS Ventura 13.3.1 Node v20
  • Other libraries you are using: "@jest/fake-timers": "^28.1.3"

What did you expect to happen?
I expect the jest.useFakeTimers() function to work out of the box.
What actually happens
It works for Node v18, but upgrading my stack to Node v19 and beyond we run into the following errors.
TypeError: Cannot assign to read only property 'performance' of object '[object global]' and
Can't install fake timers twice on the same global object.
jest.useFakeTimers() is backed by @sinon/fake-timers Jest-Reference
How to reproduce
Have the latest node and jest versions installed

brew install node 
npm install --save-dev jest

and attempt to call `jest.useFakeTimers() ie:

jest.useFakeTimers()

will result in failures.

Similar issues noted here: Bug and perhaps related to this

@musojames
Copy link

I've run into the same issue with node 19.0.1 on Mac OS Monterrey 12.6

@mrazauskas
Copy link

mrazauskas commented Apr 26, 2023

How to reproduce
Have the latest node and jest versions installed

Above you mention that "@jest/fake-timers": "^28.1.3" is installed. The latest Jest version v29.5.0.

Which one did you actually use? The latest one or v28? Did you try upgrading to the latest one?


If upgrading does not help, since Jest v28 you can excluding performance from the list of faked APIs: jest.useFakeTimers({doNotFake: ['performance']});

Reference: jestjs/jest#12055 (comment)

@fatso83
Copy link
Contributor

fatso83 commented Apr 26, 2023

@charlieyeng Reproducible with Jest 28. Not reproducible with Jest 29 and Node 19. This means you need to upgrade your Jest version.

$ cat test/foo.test.js

test('hey', () => {
   jest.useFakeTimers()
})

$ npx jest test/foo.test.js
 PASS  test/foo.test.js
  ✓ hey

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        0.155 s
Ran all test suites matching /test\/foo.test.js/i.

@fatso83 fatso83 closed this as completed Apr 26, 2023
@SimenB
Copy link
Member

SimenB commented Apr 26, 2023

Duplicate of #438, fwiw

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants