The combination of Jest and React native version 0.56 may have some problems and these steps should be fix those problems.
yarn test
yarn run v1.7.0
$ jest
FAIL __tests__/timeline_form_screen_test.js
● Test suite failed to run
Plugin 0 specified in "/ReactNative/AppName/node_modules/babel-preset-react-native/index.js" provided an invalid property of "default" (While processing preset: "/ReactNative/AppName/node_modules/babel-preset-react-native/index.js")
at Plugin.init (node_modules/babel-core/lib/transformation/plugin.js:131:13)
at Function.normalisePlugin (node_modules/babel-core/lib/transformation/file/options/option-manager.js:152:12)
at node_modules/babel-core/lib/transformation/file/options/option-manager.js:184:30
at Array.map (<anonymous>)
at Function.normalisePlugins (node_modules/babel-core/lib/transformation/file/options/option-manager.js:158:20)
at OptionManager.mergeOptions (node_modules/babel-core/lib/transformation/file/options/option-manager.js:234:36)
at node_modules/babel-core/lib/transformation/file/options/option-manager.js:265:14
at node_modules/babel-core/lib/transformation/file/options/option-manager.js:323:22
at Array.map (<anonymous>)
at OptionManager.resolvePresets (node_modules/babel-core/lib/transformation/file/options/option-manager.js:275:20)
If you got erro above, rename .babelrc to .babel.config.js on your React Native project root and will fix the error.
However still may have another error.
/ReactNative/AppName/__tests__/component_test.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import React from 'react';
^^^^^
SyntaxError: Unexpected identifier
at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:403:17)
Modify package.json like below.
"jest": {
"preset": "react-native"
}
to
"jest": {
"preset": "react-native",
"transform": {
"^.+\\.js$": "<rootDir>/node_modules/react-native/jest/preprocessor.js"
}
}
Then it will fix the error.
Top comments (0)