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

Đang mở
#4,689 4 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

@m-bert đang làm issue này rồi.

Từ ngày 13/11/2026.

  • #4694 của @m-bert — đang mở

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
72/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
javascript, react-native, typescript
Lĩnh vực
frontend, testing

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
TypeScript
Star
6.8k
Fork
1.1k
Merge trung bình
1 ngày 23 giờ
Pull request đã merge (30 ngày)
46

Chuẩn bị môi trường

  • Không có Dockerfile hay tệp Docker Compose
  • Có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của software-mansion/react-native-gesture-handler

Tất cả issue của software-mansion/react-native-gesture-handler

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.