我正在尝试为现有的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)
同时从jest
中删除babel-jest
和devDependencies
可以解决此问题,但是现在运行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.
要使应用程序和测试都可运行我需要做什么?
答案 0 :(得分:0)
基于No tests found
,看来您的测试可能不在正确的文件夹中。它们应该位于src
中名为__tests__
的文件夹中,并具有test.js
或spec.js
后缀。
有关更多信息,请参见此答案:Create React App cannot find tests