Jest: with the hook API, raw touch events fired under a `GestureDetector` don't reach ancestors under Testing Library 14

Ouverte
#4,656 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 2 jours

@aliassar y travaille déjà.

Depuis le 2/11/2026.

Évaluation

Difficulté
3/5
Temps estimé
1-2 jours
Accessibilité débutants
66/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
react-native, typescript
Domaine
mobile, testing

Piste de recherche

Start with the Jest mock at src/mocks/hostDetector.tsx and the hook detector at src/v3/detectors/NativeDetector.tsx, then reproduce the failing case from the linked repository with npx jest. Check how the mock and detector interact with Testing Library 14's touch event handling. Done when the parent receives touchStart in Jest under a hook gesture and the builder API case still passes.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

Platform: Android Platform: iOS
Description

This happens only in Jest: it's an interaction between Gesture Handler 3's test stand-in and React Native Testing Library, not a bug in the runtime.

Under Jest, jestSetup.js replaces HostGestureDetector with a plain View (src/mocks/hostDetector.tsx at v3.3.0). For a hook gesture, NativeDetector passes that View its onStartShouldSetResponder (NativeDetector.tsx#L76 at v3.3.0), which declines the responder.

Testing Library 14 treats a declining responder as blocking every event for the ancestors above it, raw touch events included. So fireEvent(child, 'touchStart') under a hook gesture's GestureDetector no longer reaches a parent's onTouchStart. On a device it does. (Once a gesture activates on a device, the ancestors get touchCancel, as expected: that isn't what this is about. In Jest, touchStart and the moves before activation never reach them.) With a builder-API gesture, no such View is rendered and the touch gets through, so tests that passed on 2.x start failing after moving to the hooks.

The root cause appears to be on Testing Library's side: on a device, raw touch events reach every ancestor whatever the responder does, and Testing Library applies the responder rule to them anyway. I've reported it there as callstack/react-native-testing-library#1957. I'm raising it here too because Gesture Handler 3 users will run into it when they move tests from the builder API to the hooks, so you may want to do something about it on your side, or at least be aware of it.

Steps to reproduce
  1. Clone https://github.com/jrmsayag/rntl-touch-bubbling-repro-demo and run npm ci.
  2. Run npx jest.
  3. "with a hook-API gesture (usePanGesture())" fails: the parent's onTouchStart gets 0 calls. "with a builder-API gesture (Gesture.Pan())" passes.
function Pannable() {
  const gesture = usePanGesture({});
  return (
    <GestureDetector gesture={gesture}>
      <View testID="child" />
    </GestureDetector>
  );
}

it('a raw touchStart under a hook gesture reaches the parent', async () => {
  const onTouchStart = jest.fn();
  await render(
    <GestureHandlerRootView>
      <View onTouchStart={onTouchStart}>
        <Pannable />
      </View>
    </GestureHandlerRootView>,
  );

  await fireEvent(screen.getByTestId('child'), 'touchStart');

  expect(onTouchStart).toHaveBeenCalledTimes(1); // fails: 0 calls
});
A link to a Gist, an Expo Snack or a link to a repository

https://github.com/jrmsayag/rntl-touch-bubbling-repro-demo

Gesture Handler version

3.3.0

React Native version

0.88.1

Platforms

Android, iOS (it happens in Jest, whatever the platform)

JavaScript runtime

Hermes (not relevant: Jest runs on Node)

Workflow

Using Expo Prebuild or an Expo development build (the repro itself is plain React Native with @react-native/jest-preset)

Build type

Debug mode

Device

Not applicable (Jest); pick any.

Device model

Not applicable (Jest, Node 22). @testing-library/react-native 14.1.0, Jest 30.5.2.

Acknowledgements

Yes

Langage dominant
TypeScript
Étoiles
6.8k
Forks
1.1k
Merge moyen
1 j 23 h
PR mergées (30 j)
46

Préparer son environnement

  • Aucun Dockerfile ni fichier Docker Compose
  • Propose un modèle de pull request
  • Aucun guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de software-mansion/react-native-gesture-handler

Toutes les issues de software-mansion/react-native-gesture-handler

Issues similaires

Plus d'issues TypeScript

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.