Repository navigation
Commit 5f0f0d8
## Description
Fixes #4417.
Since 3.2.0, `Pressable` dispatches between two engines:
`StatefulPressable` when one of the
relation props (`simultaneousWith` / `requireToFail` / `block`) is
passed, and
`PressableWithTouchable` otherwise — the common case.
Only `StatefulPressable` sets `testOnly_onPress` / `testOnly_onPressIn`
/ `testOnly_onPressOut` /
`testOnly_onLongPress` on the button. `PressableWithTouchable` doesn't,
so for a plain
`<Pressable onPress={...}>` React Native Testing Library finds no
handler and
`fireEvent(element, 'press')` silently does nothing.
The press state machine runs natively, so in a test environment those
props are the only way to
reach the handlers. This makes the regression silent and fairly
wide-reaching: no error is
thrown, tests just stop observing presses. On 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`.
The fix forwards the four handlers from `PressableWithTouchable` too,
guarded by `isTestEnv()`,
exactly as `StatefulPressable` does. `Touchable` spreads its remaining
props onto
`GestureHandlerButton`, which already declares them in `ButtonProps`, so
nothing else needed to
change and the props stay stripped outside a test environment.
Note this is unrelated to #4414, which fixed the `testOnly_pressed`
display state.
## Test plan
Added a regression test in `src/__tests__/mocks.test.tsx` asserting the
four `testOnly_*` props
are wired on the button for a relation-free `Pressable`. It fails on
`main` and passes with the
fix.
The test asserts the props rather than calling `fireEvent(element,
'press')` because this repo is
on `@testing-library/react-native@12.9`, which predates the `testOnly_*`
handler lookup (added in
v13). Asserting the props keeps the test meaningful on the pinned
version and independent of the
RNTL version.
In `packages/react-native-gesture-handler`:
- `yarn test` — 16 suites, 135 tests passing
- `yarn ts-check` — clean
- `yarn lint:js` — 0 errors
- `yarn format:js` — clean
Also verified end-to-end in a real app (Expo 57 / RN 0.86, RNTL 14.0.1)
that had ~3 suites broken
by the 3.1.0 → 3.2.0 bump: with this change applied as a patch, the full
suite is green again
(136 suites, 1663 tests, 73 snapshots).
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
1 parent 44046a6 commit 5f0f0d8
2 files changed
Lines changed: 40 additions & 2 deletions
File tree
- packages/react-native-gesture-handler/src
- __tests__
- v3/components
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| |||
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| 20 | + | |
| 21 | + | |
19 | 22 | | |
20 | 23 | | |
21 | 24 | | |
| |||
314 | 317 | | |
315 | 318 | | |
316 | 319 | | |
317 | | - | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
318 | 325 | | |
319 | 326 | | |
320 | 327 | | |
| |||
0 commit comments