[Jest][3.5.0] `fireEvent.press` no longer reaches `Touchable` when its child is inside an `InterceptingGestureDetector`
メンテナーはふだん 2 日以内に返信
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 72/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- javascript, react-native, typescript
調査の方向性
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 の本文から書いたものです。
説明
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 ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドなし
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
software-mansion/react-native-gesture-handler のほかの issue
-
[Web] GestureDetector blocks context menu by default対応中かも @lassiecoder が 4 日前に担当しました。 オープンPlatform: Web
難易度 3/5 1〜2日 初心者へのやさしさ 56/100
software-mansion/react-native-gesture-handler#4687 · コメント 3 件 ·
メンテナーはふだん 2 日以内に返信
-
[Android] v3 `ReanimatedSwipeable` takes over a vertical scroll in a React Native list once the finger drifts 10 dp sideways再び着手できるかも @JaydeepAgravat が 10 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンPlatform: Android
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
software-mansion/react-native-gesture-handler#4670 · コメント 6 件 ·
メンテナーはふだん 2 日以内に返信
-
Jest: with the hook API, raw touch events fired under a `GestureDetector` don't reach ancestors under Testing Library 14再び着手できるかも @aliassar が 13 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンPlatform: Android Platform: iOS
難易度 3/5 1〜2日 初心者へのやさしさ 66/100
software-mansion/react-native-gesture-handler#4656 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
[Android] A held tap on a Touchable or Pressable in ScrollView does nothing while the keyboard is up対応中かも @m-bert が 6 日前に担当しました。 オープンMissing repro Platform: Android
難易度 4/5 3〜5日 初心者へのやさしさ 50/100
software-mansion/react-native-gesture-handler#4653 · コメント 7 件 ·
メンテナーはふだん 2 日以内に返信
-
[IOS] The "hitslop" attribute used in the packaging component FlatList does not work as expected.オープンClose when stale Missing repro Platform: iOS
難易度 3/5 1〜2日 初心者へのやさしさ 48/100
software-mansion/react-native-gesture-handler#4649 · コメント 2 件 ·
メンテナーはふだん 2 日以内に返信
software-mansion/react-native-gesture-handler の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
pollen-robotics/reachy-mini-desktop-app#341 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
mike-north/AgentMonitors#648 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
vercel-labs/ui#700 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 2 日以内に返信