Cannot find module 'NativeAnimatedHelper' when using Jest mock

S

saadq

Guest
I have been trying to setup react-navigation in my new React Native app. While I have the code/screens working, Jest is causing me issues after adding in the library by following the v4 docs.

I installed react-navigation, react-native-reanimated, react-native-gesture-handler, and [email protected]^1.0.0-alpha.23. I then went into the ios folder and ran pod install. Because I am on v0.61 of React Native, they should have been autolinked.

When I run the default Jest test, I get an error like:

✓ renders correctly (106ms)

console.warn node_modules/react-native/Libraries/Animated/src/NativeAnimatedHelper.js:270
Animated: `useNativeDriver` is not supported because the native animated module is missing. Falling back to JS-based animation. To resolve this, add `RCTAnimation` module to this app, or remove `useNativeDriver`. More info: https://github.com/facebook/react-native/issues/11094#issuecomment-263240420


I searched for this error, and most of the suggested answers were to put this in my test file:

jest.mock('NativeAnimatedHelper');


However, when I tried doing so, Jest complaing with an error like so:

FAIL __tests__/App-test.tsx
● Test suite failed to run

Cannot find module 'NativeAnimatedHelper' from 'App-test.tsx'

6 | import renderer from 'react-test-renderer'
7 |
> 8 | jest.mock('NativeAnimatedHelper')
| ^
9 |
10 | it('renders correctly', () => {
11 | renderer.create(<App />)

at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:259:17)
at Object.<anonymous> (__tests__/App-test.tsx:8:1)


I've been trying various things for awhile now, any help/suggestions would be appreciated!


Versions:

Node: 10.16.1
npm: 6.11.3
"react": "^16.9.0",
"react-native": "0.61.1",
"react-native-gesture-handler": "^1.4.1",
"react-native-reanimated": "^1.3.0",
"react-native-screens": "^1.0.0-alpha.23",
"react-navigation": "^4.0.10",
"react-navigation-stack": "^1.9.3",

"babel-jest": "^24.1.0"
"jest": "^24.1.0"
"react-test-renderer": "^16.9.0"


Jest config:

{
"jest": {
"preset": "react-native",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
],
"setupFiles": [
"./node_modules/react-native-gesture-handler/jestSetup.js"
],
"transformIgnorePatterns": [
"node_modules/(?!((jest-)?react-native|react-navigation|@react-navigation/.*))"
]
}
}

Continue reading...
 
Top