2

At one point in time these tests worked. Not sure when they broke. But I cannot get them to run. I get the same error every time. I've followed a few Stack Overflow posts but for some reason none of them work for me. I'll post a few links of the more popular posts I tried at the end of the post.

I get the following when running:

yarn test
Test suite failed to run

    Jest encountered an unexpected token

    Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.

    Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.

    By default "node_modules" folder is ignored by transformers.

    Here's what you can do:
     • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
     • If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
     • 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/configuration
    For information about custom transformations, see:
    https://jestjs.io/docs/code-transformation

    Details:

    SyntaxError: /Users/xxx/xxx/dev/node_modules/@react-native/polyfills/error-guard.js: Missing semicolon. (14:4)

      12 | let _inGuard = 0;
      13 |
    > 14 | type ErrorHandler = (error: mixed, isFatal: boolean) => void;
         |     ^
      15 | type Fn<Args, Return> = (...Args) => Return;
      16 |
      17 | /**

      at Object._raise (node_modules/@babel/parser/lib/index.js:506:17)
      at Object.raiseWithData (node_modules/@babel/parser/lib/index.js:499:17)
      at Object.raise (node_modules/@babel/parser/lib/index.js:460:17)
      at Object.semicolon (node_modules/@babel/parser/lib/index.js:3677:10)
      at Object.parseExpressionStatement (node_modules/@babel/parser/lib/index.js:14525:10)
      at Object.parseStatementContent (node_modules/@babel/parser/lib/index.js:14090:19)
      at Object.parseStatement (node_modules/@babel/parser/lib/index.js:13942:17)
      at Object.parseBlockOrModuleBlockBody (node_modules/@babel/parser/lib/index.js:14567:25)
      at Object.parseBlockBody (node_modules/@babel/parser/lib/index.js:14558:10)
      at Object.parseProgram (node_modules/@babel/parser/lib/index.js:13861:10)

Here are the important parts (I think) of my package.json file:

"devDependencies": {
    "@babel/core": "^7.16.12",
    "@babel/preset-env": "^7.16.11",
    "@babel/preset-react": "^7.16.7",
    "@testing-library/jest-native": "^4.0.4",
    "@testing-library/react-native": "^9.0.0",
    "babel-jest": "^27.4.6",
    "jest": "^27.4.7",
    "reactotron-react-native": "^5.0.0"
  },
  "jest": {
    "preset": "react-native",
    "setupFilesAfterEnv": [
      "@testing-library/jest-native/extend-expect"
    ],
    "setupFiles": [
      "./jest.setup.js"
    ],
    "transformIgnorePatterns": [
      "node_modules/(?!(jest-)?@?react-native|react-clone-referenced-element|@react-native-community|expo(nent)?|@expo(nent)?/.*|react-navigation|@react-navigation/.*|@unimodules/.*|unimodules|@codler/react-native-keyboard-aware-scroll-view|@expo|@sentry|sentry-expo|react-native-vector-icons|@expo/vecto|@react-native-picker|native-base|@sentry/.*)",
      "node_modules/@react-native/"
    ],
    "collectCoverage": true,
    "collectCoverageFrom": [
      "**/*.{js,jsx}",
      "!**/coverage/**",
      "!**/node_modules/**",
      "!**/babel.config.js",
      "!**/jest.setup.js"
    ]
  }

I've also tried the following patterns:

1. node_modules/(?!@react-native|react-native)/

2. node_modules/(?!(jest-)?@react-native|react-(native|universal|navigation)-(.*)|@react-native-community/(.*)|@react-navigation/(.*)|bs-platform|(@[a-zA-Z]+/)?(bs|reason|rescript)-(.*)+)

I read a post that said I needed a babel.config.js. Here that is:

module.exports = {
  presets: ['@babel/preset-env', '@babel/preset-react'],
  plugins: ["@babel/plugin-transform-runtime"]
};

And as promised, here are some of the threads I've looked to to no avail:

  1. jest config is throwing "type ErrorHandler = (error: mixed, isFatal: boolean) => void" after update to 26.x
  2. Jest transformIgnorePatterns not working
  3. How can I stop my React Native tests bombing out on Flow types in Node Modules?
blacKnight
  • 73
  • 7
  • 1
    Can you post the entire error message & stack, unedited and as text? It's cut off in your screenshot. – phihag Jan 27 '22 at 23:06
  • Just posted it as text – blacKnight Jan 27 '22 at 23:33
  • Did you found a solutions? having the same problem @blacKnight – miguelacio Sep 22 '22 at 02:21
  • @miguelacio I did fix this issue. I can't remember what I did to fix it. But my mode.exports look like this now: `module.exports = { presets: ['babel-preset-expo', "module:metro-react-native-babel-preset"], plugins: ["@babel/plugin-transform-runtime", "react-native-reanimated/plugin"] };` – blacKnight Sep 28 '22 at 02:42

0 Answers0