I am trying to set up tests for the existing React app. We are using React 16.8.13
After some struggle I've made it work. For that I had to install jest 24.9.0
and babel-jest 24.9.0
. The tests run fine and I am getting a coverage report. However when I run yarn start
I am getting an error:
The react-scripts package provided by Create React App requires a dependency:
"babel-jest": "23.6.0"
Don't try to install it manually: your package manager does it automatically.
However, a different version of babel-jest was detected higher up in the tree:
/<Path to my App>/node_modules/babel-jest (version: 24.9.0)
removing both jest
and babel-jest
from devDependencies
fixes the issue, but now running yarn test
gives me an error:
No tests found
In /<Path to my App>
32 files checked.
testMatch: - 32 matches
testPathIgnorePatterns: /node_modules/ - 32 matches
testRegex: (\/tests\/.*\.test)\.[jt]sx?$ - 0 matches
Pattern: - 0 matches
error Command failed with exit code 1.
What do I need to do to have both app and tests runnable?
Based on the No tests found
, it looks like your tests might not be in the right folder. They should be in a folder in src
called __tests__
and have a test.js
or spec.js
suffix.
See this answer for more info: Create React App cannot find tests
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.