I run jest in Travis CI, get this error:
ERROR
My package.json:
"dependencies": {
"react": "~15.4.1",
"react-native": "^0.38.0",
...
},
"jest": {
"preset": "jest-react-native"
},
"devDependencies": {
"babel-jest": "^17.0.2",
"babel-preset-react-native": "^1.9.0",
"jest": "^17.0.3",
"jest-react-native": "^17.0.3",
"react-test-renderer": "^15.4.1",
...
}
But on my local PC is right.
How to solve?
I guess this error occured when system OS is Linux.
Because the same project OSX ci log is right.
And my local PC is mac.
Same issue with Travis CI since upgrading to :
"react": "~15.4.1",
"react-native": "^0.38.0"
This runs fine :
"react": "~15.3.1",
"react-native": "^0.37.0"
From what I can see React Native 0.38 asks you to use React 15.4.0 RC 4.
Have you tried using it instead of 15.4.1?
Also related: https://github.com/facebook/jest/issues/1840.
@gaearon I have the same issue. react@~15.4.1 actually resolves to React 15.0.4-rc.4 right now so this is not the issue...
@gaearon When run react-native init, [email protected] will generate in package.json.
@Richard-Cao look at this https://github.com/facebook/jest/issues/1840#issuecomment-263004102 You could try react-15.4.0-rc.2 as a temporary solution.
Adding "^React$": "<rootDir>/node_modules/react" to moduleNameMapper of jest-react-native/jest-preset.json also helps. Maybe it was forgotten to update for jest release.
As another (slightly better) workaround, I'm adding this to package.json:
"jest": {
...
"moduleNameMapper": {
"^React$": "<rootDir>/node_modules/react"
}
}
@donataswix there is another solution. I can say, "fix" :)
https://github.com/facebook/react/issues/8442#issuecomment-263474956
I see
"jest": {
"preset": "react-native"
}
create by react-native init, but
"jest": {
"preset": "jest-react-native"
}
What we should choose?
@Richard-Cao I suppose, it depends on used react-native version
"preset": "react-native"when using RN 0.38+
@ColCh Thx~
I'll update jest-react-native today to forward to react-native. I'm also updating Jest's documentation to hint that you won't need jest-react-native any longer as the default setup with 0.38 includes a working Jest configuration.
See #2182.
Most helpful comment
Adding
"^React$": "<rootDir>/node_modules/react"tomoduleNameMapperofjest-react-native/jest-preset.jsonalso helps. Maybe it was forgotten to update for jest release.As another (slightly better) workaround, I'm adding this to
package.json: