Jest broken: “Cannot read property ‘Direction’ of undefined” in 1.10.1

Description

This issue is happening consistently in tests as of 1.10.1. Reverting to 1.9.0, with no other changes (or a previous version) fixes the issue.

Cannot read property ‘Direction’ of undefined

Screenshots

image

Steps To Reproduce

1.Run Jest tests involving react-native-gesture-handler in 1.10.1? I don’t have a minimal repro but there are at least several other users experiencing this:

Expected behavior

Tests pass

Actual behavior

Tests break because of this error message

Snack or minimal code example

(I just reverted to 1.9.0 – I’m hoping this is clear enough and someone can quickly diagnose based on the diff.)

Package versions

  • React: react@16.13.1
  • React Native: react-native@0.63.4
  • React Native Gesture Handler: 1.10.1

4 thoughts on “Jest broken: “Cannot read property ‘Direction’ of undefined” in 1.10.1

  1. Does replacing node_modules/react-native-gesture-handler/jestSetup.js with this content:

    import { View, ScrollView } from 'react-native';
    
    const NOOP = () => {
      // do nothing
    };
    
    const mockModule = {
        ScrollView,
        PanGestureHandler: View,
        attachGestureHandler: NOOP,
        createGestureHandler: NOOP,
        dropGestureHandler: NOOP,
        updateGestureHandler: NOOP,
        Direction: {
          RIGHT: 1,
          LEFT: 2,
          UP: 4,
          DOWN: 8,
        },
        State: {
          BEGAN: 'BEGAN',
          FAILED: 'FAILED',
          ACTIVE: 'ACTIVE',
          END: 'END',
          UNDETERMINED: 'UNDETERMINED',
        }};
    
    jest.mock('./src/RNGestureHandlerModule', () => mockModule);
    jest.mock('./dist/src/RNGestureHandlerModule', () => mockModule);

    resolve this issue for you?