-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Description
Version
4.5.11
Reproduction link
https://github.com/Robin-Hoodie/test-jest-modern-faketimers
Environment info
System:
OS: macOS 11.1
CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
Binaries:
Node: 15.0.1 - ~/.nvm/versions/node/v15.0.1/bin/node
Yarn: 1.22.5 - ~/.yarn/bin/yarn
npm: 7.0.3 - ~/.nvm/versions/node/v15.0.1/bin/npm
Browsers:
Chrome: 88.0.4324.96
Edge: 88.0.705.53
Firefox: 84.0.2
Safari: 14.0.2
npmPackages:
@vue/cli-plugin-unit-jest: ^4.5.11 => 4.5.11
@vue/cli-shared-utils: 4.5.11
jest-serializer-vue: 2.0.2
vue-jest: 3.0.7
vue-template-es2015-compiler: 1.9.1
npmGlobalPackages:
@vue/cli: Not Found
Steps to reproduce
- Clone repo
- Run command "yarn jest"
What is expected?
Using Jest's fakeTimers in modern mode should work (https://jestjs.io/blog/2020/05/05/jest-26#new-fake-timers)
What is actually happening?
An error is thrown: "TypeError: setSystemTime is not available when not using modern timers"
I'm honestly not sure whether this is a Jest issue, a Vue CLI issue or a Yarn issue.
This can be fixed by removing the dependency on @vue/cli-plugin-unit-jest entirely, though that's obviously not ideal.
It seems that somehow, running jest while having a dependency on @vue/cli-plugin-unit-jest will still use jest@24
Even overwriting the jest@24 dependency to jest@26 using Yarn resolutions does not fix the issue.
I bumped into this while working on a monorepo where I have have 2 sub packages in my workspace:
- A server package in which tests are run with
jest - A client (Vue) package in which tests are run with
vue-cli-service test:unit
(The error message is slightly different there, logging "TypeError: Cannot read property 'useFakeTimers' of undefined", though the root cause is likely the same)
EDIT: Just found out that installing dependencies with npm i (first removing yarn.lock and node_modules) will actually also fix this (though that doesn't convince me yet that this is a yarn issue)
EDIT#2: Using yarn 2 to install dependencies also removes this problem