Hello-World
Hello-World

Reputation: 9555

Jest test not passing in create react app

Please can you help me to get my jest tests to run. My create-react-app (es6) with redux builds and runs in the browser as expected.

I think there is something wrong with my imports in jest, but not sure what.

Can you please help me to understand why my jest test is failing?


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

● Test suite failed to run

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/tests/App.test.js ● Test suite failed to run

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)

Test Suites: 2 failed, 2 total Tests: 0 total Snapshots: 0 total Time: 4.715s Ran all test suites.

Watch Usage: Press w to show more.

Upvotes: 0

Views: 1489

Answers (1)

Matt Carlotta
Matt Carlotta

Reputation: 19762

Looks like you're just missing the react-redux and redux dependencies.

Simply install them: npm install redux react-redux and your tests will pass.

Upvotes: 3

Related Questions