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?

skyboyer
  • 22,209
  • 7
  • 57
  • 64
SaroVin
  • 1,583
  • 3
  • 23
  • 46

4 Answers4

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.

MikeL
  • 2,756
  • 2
  • 23
  • 41
Cesar
  • 682
  • 3
  • 15
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'"
Adrian Moisa
  • 3,923
  • 7
  • 41
  • 66
-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.

Vitaliy
  • 77
  • 4
-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",
  ...
}
mickaelw
  • 1,453
  • 2
  • 11
  • 28