0

This is from the boilerplate Expo app built with create-react-native-app

Here's the jest section of my package.json:

  "jest": {
    "preset": "react-native",
    "testEnvironment": "node"
  },

Here's the output when I attempt to run jest:

> jest

 FAIL  src/__tests__/App.js
  ● Test suite failed to run

    Jest encountered an unexpected token

    This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.

    By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".

    Here's what you can do:
     • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
     • If you need a custom transformation specify a "transform" option in your config.
     • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

    You'll find more details and examples of these config options in the docs:
    https://jestjs.io/docs/en/configuration.html

    Details:

    /home/charney/om/star-harvester-centauri/node_modules/expo/build/Expo.fx.js:1
    import './environment/react-native-logs.fx';
    ^^^^^^

    SyntaxError: Cannot use import statement outside a module

      at Runtime._execModule (node_modules/jest-runtime/build/index.js:1157:58)
      at Object.<anonymous> (node_modules/expo/src/Expo.ts:1:1)
Charney Kaye
  • 3,667
  • 6
  • 41
  • 54

1 Answers1

0

Same answer as Jest encountered an unexpected token with react-native

  "jest": {
    "preset": "react-native",
    "transform": {
      "^.+\\.js$": "<rootDir>/node_modules/react-native/jest/preprocessor.js"    },
    "testEnvironment": "node"
  },
Charney Kaye
  • 3,667
  • 6
  • 41
  • 54