-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Jest 27: modern faketimers and jest.setSystemTime #11440
Comments
That snippet runs fine. Can you post a full reproduction? |
Tested with // jest.config.js
export default {
testEnvironment: 'node',
testRunner: 'jest-circus/runner',
transform: {},
}; // unit.test.js
it('is awesome', async () => {
jest.useFakeTimers('modern');
jest.setSystemTime(new Date('2020-10-01T06:40:38Z'));
expect(true).toBe(true);
}); > jest unit.test.js
FAIL ./unit.test.js
✕ is awesome (3 ms)
● is awesome
TypeError: setSystemTime is not available when not using modern timers
1 | it('is awesome', async () => {
2 | jest.useFakeTimers('modern');
> 3 | jest.setSystemTime(new Date('2020-10-01T06:40:38Z'));
| ^
4 | expect(true).toBe(true);
5 | });
6 |
at Object.setSystemTime (../node_modules/@jest/core/node_modules/jest-runtime/build/index.js:1989:17)
at Object.<anonymous> (unit.test.js:3:8)
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 0.268 s, estimated 1 s
Ran all test suites matching /unit.test.js/i. |
Ok there is something else at play here, since I tried the same in a fresh repo and could not reproduce it. I will need to track down in the main repo what the problem might be. |
This can be closed, sorry for taking your time. Hope it might help some future user. The problem was that the package Since it has been fixed in |
No worries, glad to hear you figured it out 👍 |
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. |
🐛 Bug Report
Using modern fake (explicitly or implicitly) in Jest 27 together with
jest.setSystemTime
gives:TypeError: setSystemTime is not available when not using modern timers
To Reproduce
Expected behavior
For it to not complain.
Link to repl or repo (highly encouraged)
envinfo
The text was updated successfully, but these errors were encountered: