react-navigation / redux-helpers

Redux middleware and utils for React Navigation
Other
296 stars 43 forks source link

npm run test error #9

Closed Liruwei closed 6 years ago

Liruwei commented 6 years ago

npm run test (jest) error in a new project (react-native init), after intalled react-navigation-redux-helpers

Ashoat commented 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?

lewnelson commented 6 years ago

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.

lewnelson commented 6 years ago

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.

Ashoat commented 6 years ago

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.

Liruwei commented 6 years ago

@lewnelson it worked for me, thanks!

Ashoat commented 6 years ago

This PR will update the React Navigation Redux integration doc to include react-navigation-redux-helpers in transformIgnorePatterns for Jest configuration.