可以运行React App或使用babel-jest对其进行测试

时间:2019-11-15 01:00:06

标签: reactjs jestjs babel-jest

我正在尝试为现有的React应用设置测试。我们正在使用React 16.8.13 经过一番挣扎,我使它成功了。为此,我必须安装jest 24.9.0babel-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-jestdevDependencies可以解决此问题,但是现在运行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.

要使应用程序和测试都可运行我需要做什么?

1 个答案:

答案 0 :(得分:0)

基于No tests found,看来您的测试可能不在正确的文件夹中。它们应该位于src中名为__tests__的文件夹中,并具有test.jsspec.js后缀。

有关更多信息,请参见此答案:Create React App cannot find tests

相关问题