I am using jest with enzyme to test components of react native
I testing my root component but i get Unexpected token import and test eventually fails
"jest": {
"preset": "jest-react-native",
"setupFiles": [
"./testConfig/globalFetch.js"
]
},
I use babel-jest
How to resolve this?
You need to add the ES modules to common js transform to your babelrc.
@cpojer I understood that but my babelrc is as follows
{
"presets": [
"react-native",
]
}
I believe react native preset has es modules
Which file is throwing?
/sample/mobile-app/node_modules/rn-splash-screen/index.js:3
import {NativeModules} from "react-native";
^^^^^^
SyntaxError: Unexpected token import
at transformAndBuildScript (node_modules/jest-runtime/build/transform.js:284:10)
at Object.<anonymous> (app/store/StoreProvider.js:6:21)
at Object.<anonymous> (__tests__/components/StoreProvider.js:5:20)
And this is the root file of my app
See http://facebook.github.io/jest/docs/tutorial-react-native.html#transformignorepatterns-customization to whitelist node modules.
Most helpful comment
See http://facebook.github.io/jest/docs/tutorial-react-native.html#transformignorepatterns-customization to whitelist node modules.