【问题标题】:Jest test not passing in create react app开玩笑测试未通过创建反应应用程序
【发布时间】:2020-06-21 22:59:05
【问题描述】:

请您帮我运行我的笑话测试。 我的带有 redux 的 create-react-app (es6) 可以按预期在浏览器中构建和运行。

开玩笑地说,我认为我的导入有问题,但不确定是什么。

你能帮我理解为什么我的笑话测试失败了吗?


 FAIL  src/components/__tests__/CommentBox.test.js

● 测试套件无法运行

Cannot find module 'react' from 'Provider.js'

However, Jest was able to find:
    'components/Provider.js'

You might want to include a file extension in your import, or update your 'moduleFileExtensions', which is currently ['web.js', 'js', 'web.ts', 'ts', 'web.tsx', 'tsx', 'json', 'web.jsx', 'jsx', 'node'].

See https://jestjs.io/docs/en/configuration#modulefileextensions-array-string

  at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:259:17)
  at Object.<anonymous> (../node_modules/react-redux/lib/components/Provider.js:10:38)

失败 src/components/tests/App.test.js ● 测试套件无法运行

Cannot find module 'react' from 'Provider.js'

However, Jest was able to find:
    'components/Provider.js'

You might want to include a file extension in your import, or update your 'moduleFileExtensions', which is currently ['web.js', 'js', 'web.ts', 'ts', 'web.tsx', 'tsx', 'json', 'web.jsx', 'jsx', 'node'].

See https://jestjs.io/docs/en/configuration#modulefileextensions-array-string

However, Jest was able to find:
    '../App.js'

You might want to include a file extension in your import, or update your 'moduleFileExtensions', which is currently ['web.js', 'js', 'web.ts', 'ts', 'web.tsx', 'tsx', 'json', 'web.jsx', 'jsx', 'node'].

See https://jestjs.io/docs/en/configuration#modulefileextensions-array-string

  at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:259:17)
  at Object.<anonymous> (../node_modules/react-redux/lib/components/Provider.js:10:38)

测试套件:2 个失败,总共 2 个 测试:共 0 快照:共 0 个 时间:4.715s 运行所有测试套件。

观看用法:按 w 显示更多。

【问题讨论】:

    标签: reactjs jestjs create-react-app


    【解决方案1】:

    看起来您只是缺少 react-reduxredux 依赖项。

    只需安装它们:npm install redux react-redux,您的测试就会通过。

    【讨论】:

      猜你喜欢
      • 2021-11-30
      • 2017-01-25
      • 2020-03-02
      • 1970-01-01
      • 1970-01-01
      • 2018-07-22
      • 2019-11-22
      • 2021-02-22
      • 1970-01-01
      相关资源
      最近更新 更多