Description
Since 3.2.0, fireEvent(element, 'press') from React Native Testing Library silently does
nothing on a plain <Pressable onPress={...}>. No error is thrown — the handler is simply never
called, so assertions report 0 calls and any waitFor around the press runs until it times out.
This is a test-environment-only bug; runtime behaviour on device is unaffected.
Cause
3.2.0 split Pressable into two engines
(v3/components/Pressable.tsx):
StatefulPressable when one of simultaneousWith / requireToFail / block is passed
PressableWithTouchable otherwise — the common case
StatefulPressable sets testOnly_onPress / testOnly_onPressIn / testOnly_onPressOut /
testOnly_onLongPress on the button
(StatefulPressable.tsx#L463-L466).
PressableWithTouchable does not. Since the press state machine runs natively, those props are
the only way a test environment can reach the handlers — RNTL looks them up in
event-handler.ts.
In 3.1.0 the single v3 Pressable always forwarded them, so this is a 3.1.0 → 3.2.0 regression
for any app whose Jest suite drives a Pressable.
This is unrelated to #4414, which fixed the testOnly_pressed display state.
Expected
fireEvent(element, 'press') calls onPress, as it did on 3.1.0 and as it still does when a
relation prop is present.
Fix
PR #4416 forwards the four handlers from PressableWithTouchable too, guarded by isTestEnv(),
exactly as StatefulPressable does, and adds a regression test that fails on main.
Steps to reproduce
- In an RN project on
react-native-gesture-handler@3.2.0 and
@testing-library/react-native@>=13, make sure jest.config.js has
setupFiles: ['react-native-gesture-handler/jestSetup.js'].
- Add the test file from the repro link below.
- Run it.
- The first test fails with
Expected number of calls: >= 1 / Received number of calls: 0; the
second one — identical apart from a simultaneousWith prop — passes.
- Downgrade to
react-native-gesture-handler@3.1.0 and re-run: both pass.
A link to a Gist, an Expo Snack or a link to a repository that reproduces the bug
https://github.com/huextrat/react-native-gesture-handler/tree/repro/pressable-testonly-handlers/repro-pressable-testonly
The bug only exists under Jest, so a device reproducer would show nothing — the failing test is
the reproduction. PR #4416 also carries a regression test that fails on main.
Gesture Handler version
3.2.0
React Native version
0.86.2
Platforms
Android, iOS (the bug is platform-independent — it happens in the Jest/node environment)
JavaScript runtime
Hermes
Workflow
Using Expo Prebuild or an Expo development build
Architecture
New Architecture (Fabric)
Build type
Debug mode
Device
N/A — reproduces under Jest (jest-expo / @react-native/jest-preset), no device involved
Device model
N/A
Acknowledgements
Yes
Description
Since 3.2.0,
fireEvent(element, 'press')from React Native Testing Library silently doesnothing on a plain
<Pressable onPress={...}>. No error is thrown — the handler is simply nevercalled, so assertions report 0 calls and any
waitForaround the press runs until it times out.This is a test-environment-only bug; runtime behaviour on device is unaffected.
Cause
3.2.0 split
Pressableinto two engines(
v3/components/Pressable.tsx):StatefulPressablewhen one ofsimultaneousWith/requireToFail/blockis passedPressableWithTouchableotherwise — the common caseStatefulPressablesetstestOnly_onPress/testOnly_onPressIn/testOnly_onPressOut/testOnly_onLongPresson the button(
StatefulPressable.tsx#L463-L466).PressableWithTouchabledoes not. Since the press state machine runs natively, those props arethe only way a test environment can reach the handlers — RNTL looks them up in
event-handler.ts.In 3.1.0 the single v3
Pressablealways forwarded them, so this is a 3.1.0 → 3.2.0 regressionfor any app whose Jest suite drives a
Pressable.This is unrelated to #4414, which fixed the
testOnly_presseddisplay state.Expected
fireEvent(element, 'press')callsonPress, as it did on 3.1.0 and as it still does when arelation prop is present.
Fix
PR #4416 forwards the four handlers from
PressableWithTouchabletoo, guarded byisTestEnv(),exactly as
StatefulPressabledoes, and adds a regression test that fails onmain.Steps to reproduce
react-native-gesture-handler@3.2.0and@testing-library/react-native@>=13, make surejest.config.jshassetupFiles: ['react-native-gesture-handler/jestSetup.js'].Expected number of calls: >= 1 / Received number of calls: 0; thesecond one — identical apart from a
simultaneousWithprop — passes.react-native-gesture-handler@3.1.0and re-run: both pass.A link to a Gist, an Expo Snack or a link to a repository that reproduces the bug
https://github.com/huextrat/react-native-gesture-handler/tree/repro/pressable-testonly-handlers/repro-pressable-testonly
The bug only exists under Jest, so a device reproducer would show nothing — the failing test is
the reproduction. PR #4416 also carries a regression test that fails on
main.Gesture Handler version
3.2.0
React Native version
0.86.2
Platforms
Android, iOS (the bug is platform-independent — it happens in the Jest/node environment)
JavaScript runtime
Hermes
Workflow
Using Expo Prebuild or an Expo development build
Architecture
New Architecture (Fabric)
Build type
Debug mode
Device
N/A — reproduces under Jest (
jest-expo/@react-native/jest-preset), no device involvedDevice model
N/A
Acknowledgements
Yes