software-mansion / react-native-gesture-handler

Declarative API exposing platform native touch and gesture system to React Native.
https://docs.swmansion.com/react-native-gesture-handler/
MIT License
6.03k stars 970 forks source link

ReanimatedSwipeable > Jest > getByGestureTestId fails to find component. #3032

Closed markaustinws closed 3 weeks ago

markaustinws commented 1 month ago

Description

Trying to retrieve a swipeable component using getByGestureTestId, but it's failing. Seems that the Test ID does not get rendered

Steps to reproduce

test("GetByGestureTestId", async () => { // const swipeable = screen.getByTestId("mySwipe");

render(

  <Swipeable testID="abcd">
    <Text>Hello</Text>
  </Swipeable>

);

screen.debug();

const swipeable = getByGestureTestId("abcd");

});

Handler with id: 'abcd' cannot be found

Screen debug:

<View
  collapsable={false}
  jestAnimatedStyle={
    {
      "value": {},
    }
  }
  onLayout={[Function onRowLayout]}
  style={
    {
      "overflow": "hidden",
    }
  }
>
  <View
    collapsable={false}
    jestAnimatedStyle={
      {
        "value": {
          "pointerEvents": "auto",
          "transform": [
            {
              "translateX": 0,
            },
          ],
        },
      }
    }
    style={
      {
        "pointerEvents": "auto",
        "transform": [
          {
            "translateX": 0,
          },
        ],
      }
    }
  >
    <Text>
      Hello
    </Text>
  </View>
</View>

Snack or a link to a repository

https://snack.expo.dev/@mausti/tenacious-green-tortillas

Gesture Handler version

2.18.1

React Native version

0.74.3

Platforms

Android, iOS

JavaScript runtime

Hermes

Workflow

Expo managed workflow

Architecture

Paper (Old Architecture)

Build type

Debug mode

Device

None

Device model

No response

Acknowledgements

Yes

Glazzes commented 1 month ago

getGestureByIdmethod will retrieve the gesture object, it's not meant to bring components

// Pan gesture in some component
const pan = Gesture.Pan().withTestID("pan")

test("some tests", () => {
  render(<SomeComponent />) // Some component with the gesture shown above
 const pan = getGestureById("pan");
})

With code like this you will get the pan gesture.

markaustinws commented 1 month ago

I'm trying to get the gesture from the Swipeable component. Is this not possible?:

render(<Swipeable testID="swipeable" />);
getByGestureTestId("swipeable");

Erroring with   Handler with id: 'swipeable' cannot be found
latekvo commented 1 month ago

Hi @markaustinws,

please let me know if this PR fixes your issue.