0

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.

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.