[Jest][3.5.0] `fireEvent.press` no longer reaches `Touchable` when its child is inside an `InterceptingGestureDetector`

オープン
#4,689 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

@m-bert がすでに取り組んでいます。

2026年11月13日 から。

  • #4694 @m-bert による — オープン

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
javascript, react-native, typescript
領域
frontend, testing

調査の方向性

Start by reading useJSResponderHandler and the changes from #4530 that add onStartShouldSetResponder to InterceptingGestureDetector; inspect the Jest setup and press handling in the reproduction. Run the two fireEvent.press cases with the listed React Native Testing Library version. Done means the wrapped-child case invokes onPress once while the plain-child case continues to pass.

索引モデルが issue の本文から書いたものです。

説明

Missing info Platform: Web
Description

Since 3.5.0, fireEvent.press from @testing-library/react-native no longer reaches a Touchable's onPress when the pressed element sits inside an InterceptingGestureDetector. The same test passes on 3.4.0.

The change comes from #4530. InterceptingGestureDetector now sets onStartShouldSetResponder on its host view, and the handler from useJSResponderHandler always returns false:

const handleStartShouldSetResponder = useCallback(() => {
  if (gesture !== undefined && isSupportedGesture(gesture, countNativeAsHandled)) {
    updateResponderEventValue(jsResponderContext, true);
  }

  return false;
}, [jsResponderContext, gesture, countNativeAsHandled]);

When testing-library dispatches a press, it walks up from the target and takes the nearest element with onStartShouldSetResponder as the touch responder. If that responder returns false, testing-library treats the touch as declined and skips every onPress above it.

Steps to reproduce
import 'react-native-gesture-handler/jest-setup';

import { fireEvent, render, screen } from '@testing-library/react-native';
import { Text } from 'react-native';
import {
  GestureHandlerRootView,
  InterceptingGestureDetector,
  Touchable,
} from 'react-native-gesture-handler';

describe('fireEvent.press on a child of a Touchable', () => {
  it('reaches onPress when the child is a plain Text', async () => {
    const onPress = jest.fn();

    await render(
      <GestureHandlerRootView>
        <Touchable onPress={onPress}>
          <Text>Press me</Text>
        </Touchable>
      </GestureHandlerRootView>
    );

    await fireEvent.press(screen.getByText('Press me'));

    expect(onPress).toHaveBeenCalledTimes(1); // passes
  });

  it('reaches onPress when the Text is wrapped in an InterceptingGestureDetector', async () => {
    const onPress = jest.fn();

    await render(
      <GestureHandlerRootView>
        <Touchable onPress={onPress}>
          <InterceptingGestureDetector>
            <Text>Press me</Text>
          </InterceptingGestureDetector>
        </Touchable>
      </GestureHandlerRootView>
    );

    await fireEvent.press(screen.getByText('Press me'));

    expect(onPress).toHaveBeenCalledTimes(1); // fails on 3.5.0, passes on 3.4.0
  });
});
A link to a Gist, an Expo Snack or a link to a repository based on this template that reproduces the bug.
Gesture Handler version

3.5.0

React Native version

0.86.3

Platforms

Web

JavaScript runtime

None

Workflow

None

Build type

None

Device

None

Device model

@testing-library/react-native 14.1.0, jest 30.5.2, jest-expo 57.0.5

Acknowledgements

Yes

主要言語
TypeScript
スター
6.8k
フォーク
1.1k
平均マージ
1日 23時間
マージ済み PR(30日)
46

環境構築

  • Dockerfile・Docker Compose ファイルなし
  • プルリクエストのテンプレートあり
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

software-mansion/react-native-gesture-handler のほかの issue

software-mansion/react-native-gesture-handler の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。