Search code examples
reactjsjestjsnativeenzymereact-native-gesture-handler

Jest Enzyme React Native react-native-gesture-handler Problem


I am not able to test react native App using enzyme, jest, and react-native-testing-library.

with just rendring test

it('renders correctly', () => {
  renderer.create(<App />).toJSON;
});

i get this error

FAIL tests/App-test.js ● Test suite failed to run

TypeError: Cannot read property 'Direction' of undefined

  at Object.<anonymous> (node_modules/react-native-gesture-handler/Directions.js:3:33)
  at Object.<anonymous> (node_modules/react-native-gesture-handler/GestureHandler.js:2:42)

Test Suites: 1 failed, 1 total Tests: 0 total Snapshots: 0 total Time: 1.586s Ran all test suites. npm ERR! Test failed. See above for more details.


Solution

  • Try to add this to your package.json:

    "jest": {
        "preset": "react-native",
        "setupFiles": [
          "./node_modules/react-native-gesture-handler/jestSetup.js"
        ]
      }