9

I am studying Jest and i am trying to add it to my component => github.com/bolket/react-native-scrollview-smart.

When i start my test i have this error:

$ jest 
 FAIL  lib/ScrollViewSmart.test.js
  ● Test suite failed to run

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

      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:179:17)
      at Object.<anonymous> (node_modules/react-native/jest/setup.js:30:1)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        0.492s

After many attempts i have moved the test in __DEV__ folder and the error has been resolved.

But if i run again the test, i have the error again...🤔.

Can you explain to me what is wrong?

4 Answers 4

1

I think there are multiple cases that can lead to this same error. In my case, I had node_modules added to the ignore_dirs in the .watchmanconfig file, I removed it and the error disappeared. Try running jest --no-watchman to see if watchman is the origin of the problem.

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

Comments

0

Several bugfixes were needed, and I managed to get the tests running: * Eliminates unknown "export" token: "Unexpected token export, when import not compiled libraries"

"transformIgnorePatterns": [
    "node_modules/?!(react-router)"
],
  • Removed jsdom - no longer emulating browser environment for react native. "TypeError: Cannot set property '_eventListeners' of undefined” with jest"
  • Updated: testPathIgnorePatterns to ignore all folders except "src" so we can remove roots: ["src"] which causes: "Cannot find module 'setupDevtools' from 'setup.js'"

Comments

-1

I faced with the same bug a few minutes ago. Looks like it could potentially be in your jest config in package.json. See https://github.com/facebook/jest/issues/1840#issuecomment-251037030

In my case, it worked.

Comments

-1

After many hours of search I solved this problem in my project, with:

This Jest config:

[
  "preset": "react-native",
  "rootDir": "..",
  "roots": [
    "<rootDir>"
  ],
  "setupFiles": [
    "<rootDir>/configuration/jest.setup.js"
  ],
  "transform": {
    "^.+\\.(js)$": "babel-jest",
    ".(ts|tsx)": "ts-jest"
  },
  "testRegex": "<rootDir>/__tests__/.*|\\.(test|spec)\\.(ts|tsx)$",
  "testPathIgnorePatterns": [
    "src/__tests__/.*/behavior",
    "src/__tests__/stubs/"
  ],
  "moduleFileExtensions": [
    "ts",
    "tsx",
    "js"
  ],
  "snapshotSerializers": ["enzyme-to-json/serializer"],
  ...
]

My jest setup file:

const enzyme = require('enzyme')
const Adapter = require('enzyme-adapter-react-16')

enzyme.configure({ adapter: new Adapter() })

And my packages.json:

"devDependencies": {
  "@types/enzyme": "^3.1.11",
  "@types/jest": "23.1.3",
  "@types/react": "16.4.1",
  "@types/react-native": "0.55.22",
  "babel-jest": "^23.2.0",
  "babel-preset-react-native": "4.0.0",
  "chai": "4.1.2",
  "enzyme": "3.3.0",
  "enzyme-adapter-react-16": "1.1.1",
  "enzyme-to-json": "^3.3.4",
  "jest": "23.2.0",
  "jest-html-reporter": "2.4.0",
  "react-dom": "^16.4.1",
  "remote-redux-devtools": "0.5.12",
  "ts-jest": "22.4.6",
  "typescript": "2.9.2",
  ...
}

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.