question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Jest unit tests don't work anymore with React Native 0.56.0

See original GitHub issue

I am migrating React Native from 0.55.3 to 0.56.0 but when I run Jest unit tests (that used to work with RN 0.55.3) I have such errors :

/Users/administrateur/***/***/node_modules/native-base-shoutem-theme/index.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import connectStyle from "./src/connectStyle";
                                                                                             ^^^^^^

    SyntaxError: Unexpected token import



      at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:403:17)
      at Object.<anonymous> (node_modules/native-base/dist/src/index.js:6:31)
      at Object.<anonymous> (App/Containers/Account/AccountScreen.js:1032:19)

It looks like the problem is Babel (RN 0.56.0 migrated to Babel 7) tries to transform native-base-shoutem-theme files while I added it to transformIgnorePatterns Jest configuration :

  "jest": {
   ...
    "preset": "react-native",
    "transformIgnorePatterns": [
      "node_modules/(?!(jest-)?react-native|react-navigation|native-base-shoutem-theme|native-base)"
    ]
  },

Actually it looks like the Jest transformIgnorePatterns config doesn’t work anymore.

I saw such problems on the web but no solution worked for me.

An extract from my package.json file :

  "devDependencies": {
    "@babel/core": "7.0.0-beta.51",
    "babel-core": "7.0.0-bridge.0",
    "babel-jest": "23.4.2",
    "babel-preset-react-native": "5.0.2",
    "jest": "23.4.2",
  },

Any idea how I could solve this problem ?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
thymikeecommented, Aug 9, 2018

This is an issue with default template from React Native. You need to add babel-core@7.0.0-bridge.0 to your deps and change .babelrc to babel.config.js. Please file an issue in their side or better, send a PR 😃

0reactions
github-actions[bot]commented, May 11, 2021

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Native - Jest: Broken since update to 0.56. How to fix it?
The problem is with 0.56.0. The only solution is running it with v0.55.4. either install the v0.55.4 by: npm i --save react-native@0.55.4.
Read more >
Unit Testing React without Jest - Whistlr
Unit Testing React without Jest. Jest is clearly a polished testing tool, but with the advent of Node.js 18, we really don't need...
Read more >
Testing - React Native
In this guide, we will cover different, automated ways to ensure your app works as expected, ranging from static analysis to end-to-end tests....
Read more >
React-Native Testing with Expo, Unit Testing with Jest
In this React-Native tutorial we'll learn how to do testing on both Android and iOS devices with Expo, and how to use Jest...
Read more >
React Native development tools - Part 3: Testing tools - Pusher
This is the third in a three part tutorial series on React Native development tools. In this part, look at testing with Jest...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found