我正在尝试为现有的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.我需要做什么才能让应用程序和测试都可运行?
发布于 2019-11-15 09:05:45
根据No tests found,看起来您的测试可能不在正确的文件夹中。它们应该位于src中名为__tests__的文件夹中,并带有test.js或spec.js后缀。
有关更多信息,请参阅此答案:Create React App cannot find tests
https://stackoverflow.com/questions/58868823
复制相似问题