Closed Liruwei closed 6 years ago
I'm not sure why this is occurring. What's your .babelrc
? Could you create a repo containing only react native init
+ react-navigation-redux-helpers
so I can clone it in order to reproduce the bug?
I'm also getting this error, I think it might have something to do with the fact that the library is using Flow, (for me at least). I'm trying to setup babel-jest
to transpile this module with the babel-preset-flow
preset. No luck as of yet. I'll hopefully be able to fix this and post a solution.
OK so the solution for me was to allow jest to transpile certain node_modules
. You can do this using transformIgnorePatterns. They have an example for React Native
"transformIgnorePatterns": [
"node_modules/(?!(react-native|my-project|react-native-button)/)"
]
I needed to add a few libraries in there, react-navigation-redux-helpers
included. My config looks like this:
"transformIgnorePatterns": [
"/node_modules/(?!(react-navigation-redux-helpers|react-navigation|react-native|react-native-safe-area-view)/)"
]
I also had to ensure images were being transformed as jest can't handle binary so this can be done by mocking files:
"transform": {
"^.+\\.js$": "babel-jest",
"\\.(png)$": "<rootDir>/src/__mocks__/fileMock.js"
},
I didn't need to add any more plugins or presets to my .babelrc
config. Hope this helps you out.
Thanks @lewnelson for looking into this!
Do you know if there is an issue tracking this on Jest's repo? It seems like this problem would occur for anybody that is using Flow types in-package.
@lewnelson it worked for me, thanks!
npm run test
(jest) error in a new project (react-native init), after intalledreact-navigation-redux-helpers