Closed charlieyeng closed 1 year ago
I've run into the same issue with node 19.0.1 on Mac OS Monterrey 12.6
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: https://github.com/jestjs/jest/issues/12055#issuecomment-1000415161
@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.
Duplicate of #438, fwiw
10.0.2
macOS Ventura 13.3.1
Node v20
"@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]'
andCan'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 installedand attempt to call `jest.useFakeTimers() ie:
will result in failures.
Similar issues noted here: Bug and perhaps related to this