Jest: Unexpected token import

Created on 9 Nov 2016  路  5Comments  路  Source: facebook/jest

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?

Most helpful comment

All 5 comments

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

Was this page helpful?
0 / 5 - 0 ratings