GeekyAnts / NativeBase

Mobile-first, accessible components for React Native & Web to build consistent UI across Android, iOS and Web.
https://nativebase.io/
MIT License
20.15k stars 2.38k forks source link

Jest Error - import connectStyle, { clearThemeCache } from "./src/connectStyle"; ^^^^^^ SyntaxError: Cannot use import statement outside a module #3105

Closed waspfreak closed 2 years ago

waspfreak commented 4 years ago

I have gone through these following points

Jest enzyme test Error Native Base

react-native, version

Expected behaviour

Actual behaviour

Try run test from my screen component

<!- import React from 'react'; import { Container, Content } from 'native-base';

const HomeScreen = props => { return (

); };

export default HomeScreen; -> Got this error

I add this in my transformIgnorePatterns: <!- transformIgnorePatterns: [ 'node_modules/(?!react-native|native-base|react-navigation|react-native-reanimated|react-navigation-redux-helpers|react-native-maps|@react-navigation/|@shoutem/theme|native-base-shoutem-theme|@shoutem/animation|@shoutem/ui|react-native-easy-grid|tcomb-form-native.*)/' ], ->

Is the bug present in both iOS and Android or in any one of them?

Yes

Any other additional info which would help us debug the issue quicker.

Important

If im using React native component the tst runs ok

landorid commented 4 years ago

I have the same problem with react-native-testing-library testing package too.

idhowardgj94 commented 4 years ago

facing the same problem

rajeshwarpatlolla commented 4 years ago

Anyone has a resolution for this?

teja-kandula commented 3 years ago

Came across same issue.

mkhalil49 commented 3 years ago

Add this to your jest config

"transformIgnorePatterns": [ "node_modules/(?!react-native|@shoutem|react-clone-referenced-element|native-base-shoutem-theme)" ]

fredlemieux commented 3 years ago

This solution unfortunately didn't work, are there any other solutions? It's not great if we can't use Jest for testing apps with NativeBase :-(

Add this to your jest config

"transformIgnorePatterns": [ "node_modules/(?!react-native|@shoutem|react-clone-referenced-element|native-base-shoutem-theme)" ]

monikamateeva commented 3 years ago

I am thinking of not not using Native Base... since it does not support testing with Jest . Or at least if we had a workaround? Could not configure my project to successfully use NativeBase and Jest.

rickyalmeidadev commented 3 years ago

I will share my jest.config.js, this was enough to make it work for me:

module.exports = {
  preset: 'react-native',
  setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
  transformIgnorePatterns: [
    '<rootDir>/node_modules/(?!(jest-)?react-native|native-base-shoutem-theme)'
  ]
};

My jest.setup.js does nothing but import @testing-library/jest-native/extend-expect.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.