[英]Can either run React App or tests for it with babel-jest
我正在尝试为现有的 React 应用程序设置测试。 我们正在使用React 16.8.13
经过一番努力,我让它工作了。 为此,我必须安装jest 24.9.0
和babel-jest 24.9.0
。 测试运行良好,我得到了覆盖率报告。 但是,当我运行yarn start
时出现错误:
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)
从devDependencies
中删除jest
和babel-jest
解决了这个问题,但是现在运行yarn test
给了我一个错误:
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.
我需要做什么才能使应用程序和测试都可运行?
根据No tests found
,您的测试似乎不在正确的文件夹中。 它们应该位于src
中名为__tests__
的文件夹中,并具有test.js
或spec.js
后缀。
有关更多信息,请参阅此答案: 创建 React App 找不到测试
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.