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 connectStyle Error

See original GitHub issue

I have gone through these following points

Issue Description

import React from 'react'
import Route from '../route'
import renderer from 'react-test-renderer'

test('renders correctly', () => {
    const tree = renderer.create(<Route />).toJSON();
    expect(tree).toMatchSnapshot();
});

The app working properly in normal case. But when I started jest, it gave an error like this: `Test suite failed to run

XXX\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 identifier

  at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/ScriptTransformer.js:440:17)
  at Object.<anonymous> (node_modules/native-base/src/index.js:1:1)`

node, npm, react-native, react and native-base version, expo version if used, xcode version

 node: v10.15.1
 npm: 6.4.1
"expo": "^31.0.4",
"native-base": "^2.8.1",
"react": "^16.5.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-31.0.1.tar.gz",

Expected behaviour

Passing test processing

Actual behaviour

Gives the error

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

11reactions
theharnesscommented, Feb 14, 2019

Same issue. Adding

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

to package.json solves the issue but greatly increases testing time. Haven’t found a better solution.

3reactions
GeDiezcommented, Feb 19, 2020

i found out the solution, reading into the doc of jest, it can be figured out by avoiding transform packages in the npm folder.

    "preset": "react-native",
    "transformIgnorePatterns": [
      "node_modules/(?!(react-[a-z, -]*|react-native|native-base-[a-z, -]*|react-native-[a-z, -]*)/)"
    ]
  }

notice: Im using react-native (no expo) and ignoring the native-base, react-native and react folders

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest - react-native SyntaxError: Unexpected token import
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...
Read more >
undefined. jest - You.com | The AI Search Engine You Control
Error: Cannot create styled-component for component: undefined ... React Jest Testing TypeError: Cannot read properties of undefined (reading 'current').
Read more >
VScode-jest: The Optimal Flow for Jest Based Testing in VS ...
VScode-jest: The optimal flow for Jest based testing in VS Code. Jest - Visual Studio Marketplace & click "Install". Alternatively open Visual Studio...
Read more >
Kiri, Bang! on Tumblr
src/connectStyle'; ... There has been a stack of error waiting for me. ... On testing, I encounter a problem where jest did not...
Read more >
Developers - SyntaxError: Cannot use import statement outside a ...
... ,exports,require,__dirname,__filename,global,jest){import connectStyle, { clearThemeCache } from ". ... "@types/jest": "^24.9.0", ... Gives the error.
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