Jest测试未通过create react app

问题描述 投票:0回答:1

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

我认为我的进口商品开玩笑,但不确定是什么。

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

这是我的仓库。https://github.com/code-in-time/react-testing-learn-


 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)

FAIL src / components / 测试 / 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.715秒运行所有测试套件。

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

reactjs create-react-app jest
1个回答
0
投票

好像您缺少react-reduxredux依赖项。

简单安装它们:npm install redux react-redux

© www.soinside.com 2019 - 2024. All rights reserved.