2

New to Jest as my testing suite for a React / Redux application and I am unable to run my actions tests due to this error plaguing my application:

Test suite failed to run

Cannot find module 'setupDevtools' from 'setup.js'

at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:191:17)

at Object. (node_modules/react-native/jest/setup.js:30:1)

Removing all content from my test file produces the same error. Here is my Jest config:

"jest": {
    "verbose": true,
    "preset": "jest-react-native",
    "roots": [
      "<rootDir>/src/actions/_tests_"
    ]
  }

Here are my dependencies:

  "dependencies": {
    "dotenv": "^4.0.0",
    "fhirclient": "^0.1.12",
    "full-age-calculator": "0.0.4",
    "prop-types": "^15.6.0",
    "react": "^16.2.0",
    "react-dom": "^16.2.0",
    "react-redux": "^5.0.6",
    "redux": "^3.7.2",
    "redux-thunk": "^2.2.0",
    "verror": "^1.10.0"
  },
  "devDependencies": {
    "babel-cli": "^6.26.0",
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.2",
    "babel-preset-env": "^1.6.1",
    "babel-preset-react": "^6.24.1",
    "css-loader": "^0.28.7",
    "eslint": "^4.12.1",
    "eslint-config-cerner": "^1.0.0",
    "eslint-plugin-import": "^2.8.0",
    "eslint-plugin-jsx-a11y": "^5.1.1",
    "eslint-plugin-react": "^7.5.1",
    "html-webpack-plugin": "^2.30.1",
    "jest": "^21.2.1",
    "jest-react-native": "^18.0.0",
    "node-sass": "^4.7.2",
    "react-native": "^0.51.0",
    "sass-loader": "^6.0.6",
    "style-loader": "^0.19.0",
    "webpack": "^3.10.0",
    "webpack-dev-server": "^2.9.5"
  },

I tried a few of the suggestions from this Github issue page which did not resolve my issue.

1
  • 1
    I would try more of the suggestions there, and/or post your issue there since it's related and would have more visibility with the people familiar with the problem. Commented Dec 12, 2017 at 23:13

1 Answer 1

1

I started anew today and solved my own problem. As it turns out, Babel has documentation which specifically explains how to setup Jest. In summary, here's what I did:

Install NPM Modules

npm install --save-dev babel-jest
npm install --save-dev babel-preset-env

or with one command:

npm install i -d babel-jest babel-preset-env

Create .babelrc Config File

{
  "presets": ["env"]
}

Modify package.json

{
  "scripts": {
    "test": "jest"
  },
  "jest": {
    "transform": {
      "^.+\\.jsx?$": "babel-jest"
    }
  }
}

Here is some further reading on why the env preset configuration is needed. Happy coding!

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.