Skip to content

Forward press handlers as testOnly_* in PressableWithTouchable - #4416

Merged
m-bert merged 1 commit into
software-mansion:mainfrom
huextrat:fix/pressable-with-touchable-testonly-handlers
Aug 14, 2026
Merged

m-bert merged 1 commit into
software-mansion:mainfrom
huextrat:fix/pressable-with-touchable-testonly-handlers

Conversation

@huextrat

@huextrat huextrat commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

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).

`Pressable` dispatches to `StatefulPressable` when a relation prop is
passed and to `PressableWithTouchable` otherwise. Only the former sets
`testOnly_onPress`/`onPressIn`/`onPressOut`/`onLongPress` on the button,
so in the common case (no relation props) React Native Testing Library
finds no handler and `fireEvent(element, 'press')` silently does
nothing.

The press state machine runs natively, so a test environment has no
other way to reach the handlers. Forward them from
`PressableWithTouchable` too, guarded by `isTestEnv()`, exactly as
`StatefulPressable` does.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings August 13, 2026 16:18
@coderabbitai

coderabbitai Bot commented Aug 13, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 729f145e-2fa8-4eb7-9c04-6c3ef95414ab

📥 Commits

Reviewing files that changed from the base of the PR and between 44046a6 and 5a40375.

📒 Files selected for processing (2)
  • packages/react-native-gesture-handler/src/__tests__/mocks.test.tsx
  • packages/react-native-gesture-handler/src/v3/components/PressableWithTouchable.tsx

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Improved test-environment handling for press interactions.
    • Ensured Pressable correctly forwards press, long-press, press-in, and press-out callbacks during testing.
  • Tests

    • Added coverage verifying that all supported press handlers are forwarded correctly.

Walkthrough

Changes

Pressable test callback forwarding

Layer / File(s) Summary
Environment-gated callback forwarding
packages/react-native-gesture-handler/src/v3/components/PressableWithTouchable.tsx
PressableWithTouchable forwards press, press-in, press-out, and long-press handlers through test-only Touchable props when isTestEnv is true.
Callback forwarding validation
packages/react-native-gesture-handler/src/__tests__/mocks.test.tsx
The test renders Pressable with four handlers and verifies the corresponding testOnly_* props on the rendered button.

Possibly related PRs

Suggested reviewers: m-bert

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the main change: forwarding press handlers as testOnly_* props in PressableWithTouchable.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a testing regression in the v3 Pressable implementation where the common (relation-free) engine (PressableWithTouchable) did not forward press handlers via testOnly_* props, preventing React Native Testing Library from reaching user handlers in a Jest environment.

Changes:

  • Forward onPress / onPressIn / onPressOut / onLongPress from PressableWithTouchable onto the underlying button as testOnly_* props, gated by isTestEnv().
  • Add a Jest regression test asserting these testOnly_* props are present for a relation-free v3 Pressable.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/react-native-gesture-handler/src/v3/components/PressableWithTouchable.tsx Adds isTestEnv() gating and forwards testOnly_* handler props in the Touchable-based v3 Pressable engine.
packages/react-native-gesture-handler/src/tests/mocks.test.tsx Adds a regression test verifying v3 Pressable exposes the four testOnly_* handler props on the rendered button.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@m-bert m-bert left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you ❤️

@m-bert
m-bert merged commit 4bc2dec into software-mansion:main Aug 14, 2026
5 checks passed
@m-bert m-bert mentioned this pull request Aug 14, 2026
m-bert added a commit that referenced this pull request Aug 14, 2026
## Description

Follow-up to #4416. None of the `Pressable` engines forwarded hover
handlers as `testOnly_*` props, so `fireEvent(element, 'hoverIn')` from
React Native Testing Library had no way to reach
`onHoverIn`/`onHoverOut`. RNTL resolves `testOnly_on{EventName}`
generically for any event, so exposing the props is all that's needed.

This adds `testOnly_onHoverIn`/`testOnly_onHoverOut` to the button props
and forwards them, guarded by `isTestEnv()`, from all three engines:
legacy `Pressable`, `StatefulPressable` and `PressableWithTouchable`.

Also widens the relation props
(`simultaneousWith`/`requireToFail`/`block`) from `AnyGesture` to
`AnyGesture | AnyGesture[]`. The JSDoc already promises a gesture object
or an array of gesture objects and the runtime handles arrays in both
directions (`relationUtils` flattens them into handler tags and pushes
the symmetric relation onto each array element), only the prop type was
narrowed.

## Test plan

Added tests in `src/__tests__/mocks.test.tsx` asserting the hover props
are wired on the button for both v3 engines — relation-free and routed
to `StatefulPressable` via `simultaneousWith={[]}` (which the type
widening makes legal). Both fail without the engine changes.

In `packages/react-native-gesture-handler`: `yarn test`, `yarn ts-check`
and `yarn lint:js` pass.
m-bert pushed a commit that referenced this pull request Aug 14, 2026
…4416)

## 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>
m-bert added a commit that referenced this pull request Aug 14, 2026
## Description

Follow-up to #4416. None of the `Pressable` engines forwarded hover
handlers as `testOnly_*` props, so `fireEvent(element, 'hoverIn')` from
React Native Testing Library had no way to reach
`onHoverIn`/`onHoverOut`. RNTL resolves `testOnly_on{EventName}`
generically for any event, so exposing the props is all that's needed.

This adds `testOnly_onHoverIn`/`testOnly_onHoverOut` to the button props
and forwards them, guarded by `isTestEnv()`, from all three engines:
legacy `Pressable`, `StatefulPressable` and `PressableWithTouchable`.

Also widens the relation props
(`simultaneousWith`/`requireToFail`/`block`) from `AnyGesture` to
`AnyGesture | AnyGesture[]`. The JSDoc already promises a gesture object
or an array of gesture objects and the runtime handles arrays in both
directions (`relationUtils` flattens them into handler tags and pushes
the symmetric relation onto each array element), only the prop type was
narrowed.

## Test plan

Added tests in `src/__tests__/mocks.test.tsx` asserting the hover props
are wired on the button for both v3 engines — relation-free and routed
to `StatefulPressable` via `simultaneousWith={[]}` (which the type
widening makes legal). Both fail without the engine changes.

In `packages/react-native-gesture-handler`: `yarn test`, `yarn ts-check`
and `yarn lint:js` pass.
RonenMars added a commit to RonenMars/threadbase-mobile that referenced this pull request Aug 26, 2026
…867)

Bumps
\[react-native-gesture-handler\](https://github.com/software-mansion/react-native-gesture-handler)
from 2.32.0 to 3.2.1. Release notes

_Sourced from [react-native-gesture-handler's
releases](https://github.com/software-mansion/react-native-gesture-handler/releases)._

> v3.2.1
> ------
> 
> 🐛 Bug fixes
> ------------
> 
> * Forward press handlers as `testOnly_*` in `PressableWithTouchable`
by [`@​huextrat`](https://github.com/huextrat) in
[software-mansion/react-native-gesture-handler#4416](https://redirect.github.com/software-mansion/react-native-gesture-handler/pull/4416)
> 
> 🔢 Miscellaneous
> ----------------
> 
> * Update `Pressable` props by [`@​m-bert`](https://github.com/m-bert)
in
[software-mansion/react-native-gesture-handler#4421](https://redirect.github.com/software-mansion/react-native-gesture-handler/pull/4421)
> 
> **Full Changelog**:
[https://github.com/software-mansion/react-native-gesture-handler/compare/v3.2.0...v3.2.1](https://github.com/software-mansion/react-native-gesture-handler/compare/v3.2.0...v3.2.1)
> 
> v3.2.0
> ------
> 
> ❗ Important changes
> -------------------
> 
> * feat: Adopt AGP v9 by [`@​hurali97`](https://github.com/hurali97) in
[software-mansion/react-native-gesture-handler#4263](https://redirect.github.com/software-mansion/react-native-gesture-handler/pull/4263)
> * Implement `Pressable` based on `Touchable` by
[`@​m-bert`](https://github.com/m-bert) in
[software-mansion/react-native-gesture-handler#4411](https://redirect.github.com/software-mansion/react-native-gesture-handler/pull/4411)
> * \[Android\] Add hover callbacks to Touchable by
[`@​j-piasecki`](https://github.com/j-piasecki) in
[software-mansion/react-native-gesture-handler#4396](https://redirect.github.com/software-mansion/react-native-gesture-handler/pull/4396)
> * \[iOS\] Add hover callbacks to Touchable by
[`@​j-piasecki`](https://github.com/j-piasecki) in
[software-mansion/react-native-gesture-handler#4397](https://redirect.github.com/software-mansion/react-native-gesture-handler/pull/4397)
> * \[Web\] Add hover callbacks to Touchable by
[`@​j-piasecki`](https://github.com/j-piasecki) in
[software-mansion/react-native-gesture-handler#4398](https://redirect.github.com/software-mansion/react-native-gesture-handler/pull/4398)
> * \[Web\] Refactor `Touchable` not to rely on `GestureDetector` by
[`@​j-piasecki`](https://github.com/j-piasecki) in
[software-mansion/react-native-gesture-handler#4344](https://redirect.github.com/software-mansion/react-native-gesture-handler/pull/4344)
> * \[iOS\] Refactor `Touchable` not to rely on `GestureDetector` by
[`@​j-piasecki`](https://github.com/j-piasecki) in
[software-mansion/react-native-gesture-handler#4343](https://redirect.github.com/software-mansion/react-native-gesture-handler/pull/4343)
> * \[Android\] Refactor `Touchable` not to rely on `GestureDetector` by
[`@​j-piasecki`](https://github.com/j-piasecki) in
[software-mansion/react-native-gesture-handler#4342](https://redirect.github.com/software-mansion/react-native-gesture-handler/pull/4342)
> * Fix fatal crash `Cannot read property 'translationX' of undefined`
when a touch event is serialized without `allTouches` by
[`@​huextrat`](https://github.com/huextrat) in
[software-mansion/react-native-gesture-handler#4316](https://redirect.github.com/software-mansion/react-native-gesture-handler/pull/4316)
> 
> 👍 Improvements
> ---------------
> 
> * \[Android\] Skip the underlay drawable when it can never be visible
by [`@​j-piasecki`](https://github.com/j-piasecki) in
[software-mansion/react-native-gesture-handler#4359](https://redirect.github.com/software-mansion/react-native-gesture-handler/pull/4359)
> * \[Android\] Apply the button's managed handler config once per prop
transaction by [`@​j-piasecki`](https://github.com/j-piasecki) in
[software-mansion/react-native-gesture-handler#4357](https://redirect.github.com/software-mansion/react-native-gesture-handler/pull/4357)
> * \[Android\] Configure the button's handler directly instead of
through a `ReadableMap` by
[`@​j-piasecki`](https://github.com/j-piasecki) in
[software-mansion/react-native-gesture-handler#4358](https://redirect.github.com/software-mansion/react-native-gesture-handler/pull/4358)
> 
> 🐛 Bug fixes
> ------------
> 
> * \[Android\] Guard update events to only be dispatched in ACTIVE
state by [`@​j-piasecki`](https://github.com/j-piasecki) in
[software-mansion/react-native-gesture-handler#4332](https://redirect.github.com/software-mansion/react-native-gesture-handler/pull/4332)
> * Pass empty callbacks to UI when `runOnJS` is `true` by
[`@​m-bert`](https://github.com/m-bert) in
[software-mansion/react-native-gesture-handler#4326](https://redirect.github.com/software-mansion/react-native-gesture-handler/pull/4326)
> * \[Web\] Fix incorrectly calculated `timeDelta` by
[`@​m-bert`](https://github.com/m-bert) in
[software-mansion/react-native-gesture-handler#4329](https://redirect.github.com/software-mansion/react-native-gesture-handler/pull/4329)
> * \[Web\] Fix incorrect `Tap` offset by
[`@​m-bert`](https://github.com/m-bert) in
[software-mansion/react-native-gesture-handler#4330](https://redirect.github.com/software-mansion/react-native-gesture-handler/pull/4330)
> * Fix `minVelocity` props behavior by
[`@​m-bert`](https://github.com/m-bert) in
[software-mansion/react-native-gesture-handler#4327](https://redirect.github.com/software-mansion/react-native-gesture-handler/pull/4327)
> * \[Android\] Fix `minDistance` being reset by partial config updates
by [`@​m-bert`](https://github.com/m-bert) in
[software-mansion/react-native-gesture-handler#4347](https://redirect.github.com/software-mansion/react-native-gesture-handler/pull/4347)
> * Move Interceptor on `ScrollView`, not its content by
[`@​m-bert`](https://github.com/m-bert) in
[software-mansion/react-native-gesture-handler#4331](https://redirect.github.com/software-mansion/react-native-gesture-handler/pull/4331)
> * \[iOS\] Re-sync layer opacity and transform from retained props when
recycling buttons by [`@​m-bert`](https://github.com/m-bert) in
[software-mansion/react-native-gesture-handler#4360](https://redirect.github.com/software-mansion/react-native-gesture-handler/pull/4360)
> * \[Android\] Properly handle `requestDisallowInterceptTouchEvent` for
v3 by [`@​j-piasecki`](https://github.com/j-piasecki) in
[software-mansion/react-native-gesture-handler#4367](https://redirect.github.com/software-mansion/react-native-gesture-handler/pull/4367)
> * Fix `Touchable` not respecting `keyboardShouldPersistTaps="handled"`
by [`@​m-bert`](https://github.com/m-bert) in
[software-mansion/react-native-gesture-handler#4372](https://redirect.github.com/software-mansion/react-native-gesture-handler/pull/4372)
> * \[macOS\] Fix touch events never being delivered by
[`@​m-bert`](https://github.com/m-bert) in
[software-mansion/react-native-gesture-handler#4390](https://redirect.github.com/software-mansion/react-native-gesture-handler/pull/4390)
> * fix: crash when mount listener fires after GestureDetector unmount
by [`@​kosmydel`](https://github.com/kosmydel) in
[software-mansion/react-native-gesture-handler#4268](https://redirect.github.com/software-mansion/react-native-gesture-handler/pull/4268)
> * \[macOS\] Fix `Pan` activation criteria being ignored by
[`@​m-bert`](https://github.com/m-bert) in
[software-mansion/react-native-gesture-handler#4387](https://redirect.github.com/software-mansion/react-native-gesture-handler/pull/4387)
> * \[macOS\] Fix `manualActivation` never blocking gesture activation
by [`@​m-bert`](https://github.com/m-bert) in
[software-mansion/react-native-gesture-handler#4389](https://redirect.github.com/software-mansion/react-native-gesture-handler/pull/4389)
> * \[iOS\] Fix touch events never being delivered to `VirtualDetector`
handlers by [`@​m-bert`](https://github.com/m-bert) in
[software-mansion/react-native-gesture-handler#4392](https://redirect.github.com/software-mansion/react-native-gesture-handler/pull/4392)
> * \[iOS\] Fix gestures attached via `VirtualGestureDetector` never
recognizing continuous gestures by
[`@​m-bert`](https://github.com/m-bert) in
[software-mansion/react-native-gesture-handler#4393](https://redirect.github.com/software-mansion/react-native-gesture-handler/pull/4393)
> * \[macOS\] Fix `Fling` not sending touch events and begin/end states
consistently by [`@​m-bert`](https://github.com/m-bert) in
[software-mansion/react-native-gesture-handler#4395](https://redirect.github.com/software-mansion/react-native-gesture-handler/pull/4395)
> * \[Android\] Fix handlers cancelled while awaiting leaking in the
orchestrator by [`@​m-bert`](https://github.com/m-bert) in
[software-mansion/react-native-gesture-handler#4402](https://redirect.github.com/software-mansion/react-native-gesture-handler/pull/4402)

... (truncated)

Commits

*
[`62f0f7d`](software-mansion/react-native-gesture-handler@62f0f7d)
Release v3.2.1
*
[`4716425`](software-mansion/react-native-gesture-handler@4716425)
Merge branch '3.2-stable' of
github.com:software-mansion/react-native-gesture...
*
[`f0ae48c`](software-mansion/react-native-gesture-handler@f0ae48c)
Update `Pressable` props
([#4421](https://redirect.github.com/software-mansion/react-native-gesture-handler/issues/4421))
*
[`5f0f0d8`](software-mansion/react-native-gesture-handler@5f0f0d8)
Forward press handlers as `testOnly_*` in `PressableWithTouchable`
([#4416](https://redirect.github.com/software-mansion/react-native-gesture-handler/issues/4416))
*
[`0a91db7`](software-mansion/react-native-gesture-handler@0a91db7)
Release v3.2.0
*
[`44046a6`](software-mansion/react-native-gesture-handler@44046a6)
\[Android\] Resolve the button event dispatcher by react tag
([#4415](https://redirect.github.com/software-mansion/react-native-gesture-handler/issues/4415))
*
[`2469c1d`](software-mansion/react-native-gesture-handler@2469c1d)
Derive `Pressable` pressed state from `testOnly_pressed`
([#4414](https://redirect.github.com/software-mansion/react-native-gesture-handler/issues/4414))
*
[`3f1bf74`](software-mansion/react-native-gesture-handler@3f1bf74)
Clear pending timers on unmount in StatefulPressable
([#4413](https://redirect.github.com/software-mansion/react-native-gesture-handler/issues/4413))
*
[`50ae6a1`](software-mansion/react-native-gesture-handler@50ae6a1)
\[General\] Default GestureDetector moduleId to -1
([#4412](https://redirect.github.com/software-mansion/react-native-gesture-handler/issues/4412))
*
[`8b661c9`](software-mansion/react-native-gesture-handler@8b661c9)
Implement `Pressable` based on `Touchable`
([#4411](https://redirect.github.com/software-mansion/react-native-gesture-handler/issues/4411))
* Additional commits viewable in [compare
view](software-mansion/react-native-gesture-handler@v2.32.0...v3.2.1)
m-bert added a commit that referenced this pull request Sep 11, 2026
Follow-up to #4416. None of the `Pressable` engines forwarded hover
handlers as `testOnly_*` props, so `fireEvent(element, 'hoverIn')` from
React Native Testing Library had no way to reach
`onHoverIn`/`onHoverOut`. RNTL resolves `testOnly_on{EventName}`
generically for any event, so exposing the props is all that's needed.

This adds `testOnly_onHoverIn`/`testOnly_onHoverOut` to the button props
and forwards them, guarded by `isTestEnv()`, from all three engines:
legacy `Pressable`, `StatefulPressable` and `PressableWithTouchable`.

Also widens the relation props
(`simultaneousWith`/`requireToFail`/`block`) from `AnyGesture` to
`AnyGesture | AnyGesture[]`. The JSDoc already promises a gesture object
or an array of gesture objects and the runtime handles arrays in both
directions (`relationUtils` flattens them into handler tags and pushes
the symmetric relation onto each array element), only the prop type was
narrowed.

Added tests in `src/__tests__/mocks.test.tsx` asserting the hover props
are wired on the button for both v3 engines — relation-free and routed
to `StatefulPressable` via `simultaneousWith={[]}` (which the type
widening makes legal). Both fail without the engine changes.

In `packages/react-native-gesture-handler`: `yarn test`, `yarn ts-check`
and `yarn lint:js` pass.
m-bert pushed a commit that referenced this pull request Nov 9, 2026
)

## Description

In a test environment both v3 `Pressable` engines
(`PressableWithTouchable` and `StatefulPressable`) forward the user's
callbacks to the button as `testOnly_onPress` / `testOnly_onPressIn` /
`testOnly_onPressOut` / `testOnly_onLongPress` / `testOnly_onHoverIn` /
`testOnly_onHoverOut`. The press state machine runs natively, so that is
how testing-library reaches them (context: #4417, #4416).

They are forwarded regardless of `disabled`, though.
`@testing-library/react-native` (13.1 and later) looks up a press
handler as `onPress` and falls back to `testOnly_onPress` (same for the
other events). None of its enabled checks (`pointerEvents`, a
non-editable `TextInput`, a responder declining in
`onStartShouldSetResponder`) applies to the RNGH button, which only sets
`onStartShouldSetResponderCapture`. So nothing marks the button as
disabled, and `fireEvent.press()`, `userEvent.press()` and
`userEvent.longPress()` on `<Pressable disabled onPress={fn}>` call `fn`
in tests. On a device the button is rendered with `enabled={false}` and
nothing fires.

That is a test-only false positive: a test asserting that a disabled
`Pressable` can't be pressed fails, and a test can't catch a regression
in the disabled state. We ran into it when bumping an app to 3.3.0 with
RNTL 14: a test checking that a cancel button can't be pressed while a
request is pending (`disabled`) started failing. Our workaround is
mocking the v3 `Pressable` with React Native's `Pressable` in our Jest
setup.

Repro (RNTL 14):

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

test('a disabled Pressable does not call onPress', async () => {
  const onPress = jest.fn();

  await render(
    <GestureHandlerRootView>
      <Pressable disabled onPress={onPress}>
        <Text>Cancel</Text>
      </Pressable>
    </GestureHandlerRootView>
  );

  await fireEvent.press(screen.getByText('Cancel'));

  expect(onPress).not.toHaveBeenCalled(); // fails: called once
});
```

### Fix

In a test environment, both engines now swap each callback a disabled
`Pressable` was given for a no-op in its `testOnly_*` prop, so
testing-library stops at the button without running anything. Dropping
the prop instead makes testing-library fall back to handlers further up
the tree. For `PressableWithTouchable` those are the ones `Touchable`
gets, so a bare `fireEvent(button, 'pressIn')` throws reading `event.x`,
and a `pressIn` followed by `press` inside `hitSlop` still fires
`onPressIn` and `onPress` (see the review thread). The hover callbacks
are swapped too. Every platform masks hover on a disabled button
(`effectiveHover` is `isHovered && enabled` on Android, iOS/macOS and
web), and `StatefulPressable`'s hover gesture is `enabled: disabled !==
true`.

Callbacks that weren't given stay unset, as on an enabled button.
Testing-library then keeps looking further up the tree for them, as it
does on `main`, so pressing a disabled `Pressable` that has no `onPress`
still reaches an enabled `Pressable` or `Touchable` around it. As on
`main`, a bare `fireEvent(button, 'pressIn')` on a disabled `Pressable`
without `onPressIn` still throws.

Nothing changes outside a test environment or for an enabled
`Pressable`, so #4417 stays fixed. The handlers `Touchable` gets are
left alone on purpose: the native button still reports press-out and
hover-out when it gets disabled mid-press or mid-hover, and `Pressable`
needs them to reset `pressed` and call `onPressOut` / `onHoverOut`.

`LegacyPressable` has the same wiring, but `jestSetup.js` replaces it
with React Native's `Pressable`, which honours `disabled`, so I left it
alone. #3612 fixed the same kind of bug for the legacy buttons'
`enabled` prop.

## Test plan

- Added a regression test to `src/__tests__/mocks.test.tsx` that runs on
both engines. It calls each `testOnly_*` handler of a disabled
`Pressable` without an event, the way a bare `fireEvent(button,
'pressIn')` does, and checks that nothing throws and none of the
callbacks fire. It also checks that a disabled `Pressable` without
callbacks leaves the `testOnly_*` props unset. It fails on `main`, where
the user's callbacks fire, and passes with this change. Like #4416, it
checks the props instead of calling `fireEvent`, because this repo pins
`@testing-library/react-native@12.9`, and that version doesn't look up
`testOnly_*` props.
- Ran a throwaway suite (not committed) against
`@testing-library/react-native` 13.3.3 and 14.1.0 on both engines,
mapped in through a scratch Jest config. For a disabled `Pressable`
given all six callbacks, it covers bare `fireEvent` calls with `press`,
`pressIn`, `pressOut`, `longPress` and `hoverOut`, a `pressIn` followed
by `press` with an event (with and without `hitSlop`), `hoverIn` with an
event, `fireEvent.press` on the button and on a child `Text`,
`userEvent.press` and `userEvent.longPress`:
  - On `main`, every one of them fires the matching callbacks.
  - With this change none of them fires anything or throws.
- On an enabled `Pressable`, `fireEvent.press` and `userEvent.press`
still fire the callbacks.
- On `PressableWithTouchable`, native `buttonPressOut` /
`buttonHoverOut` events dispatched after it gets disabled mid-press /
mid-hover still call `onPressOut` / `onHoverOut` and reset `pressed`.
- Ran a second throwaway suite on 12.9, 13.3.3 and 14.1.0 with a
disabled `Pressable` (both engines) inside an enabled `Pressable` or
`Touchable`. It covers `fireEvent.press` on the inner button and on its
`Text`, a bare `fireEvent(button, 'pressIn')`, and `userEvent.press`:
- With callbacks of its own, nothing fires on 13.3.3 and 14.1.0. On
`main` the inner callbacks fire.
- Without callbacks, every case behaves as on `main`, including the
enclosing `onPress` firing where it did before.
  - On 12.9 every case behaves as on `main`.
- In `packages/react-native-gesture-handler`:
  - `yarn test`: 26 suites, 258 tests pass.
  - `yarn ts-check`: clean.
- `yarn lint:js`: 0 errors and no warnings in the touched files. The
Prettier check is clean.
m-bert pushed a commit that referenced this pull request Dec 1, 2026
)

## Description

In a test environment both v3 `Pressable` engines
(`PressableWithTouchable` and `StatefulPressable`) forward the user's
callbacks to the button as `testOnly_onPress` / `testOnly_onPressIn` /
`testOnly_onPressOut` / `testOnly_onLongPress` / `testOnly_onHoverIn` /
`testOnly_onHoverOut`. The press state machine runs natively, so that is
how testing-library reaches them (context: #4417, #4416).

They are forwarded regardless of `disabled`, though.
`@testing-library/react-native` (13.1 and later) looks up a press
handler as `onPress` and falls back to `testOnly_onPress` (same for the
other events). None of its enabled checks (`pointerEvents`, a
non-editable `TextInput`, a responder declining in
`onStartShouldSetResponder`) applies to the RNGH button, which only sets
`onStartShouldSetResponderCapture`. So nothing marks the button as
disabled, and `fireEvent.press()`, `userEvent.press()` and
`userEvent.longPress()` on `<Pressable disabled onPress={fn}>` call `fn`
in tests. On a device the button is rendered with `enabled={false}` and
nothing fires.

That is a test-only false positive: a test asserting that a disabled
`Pressable` can't be pressed fails, and a test can't catch a regression
in the disabled state. We ran into it when bumping an app to 3.3.0 with
RNTL 14: a test checking that a cancel button can't be pressed while a
request is pending (`disabled`) started failing. Our workaround is
mocking the v3 `Pressable` with React Native's `Pressable` in our Jest
setup.

Repro (RNTL 14):

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

test('a disabled Pressable does not call onPress', async () => {
  const onPress = jest.fn();

  await render(
    <GestureHandlerRootView>
      <Pressable disabled onPress={onPress}>
        <Text>Cancel</Text>
      </Pressable>
    </GestureHandlerRootView>
  );

  await fireEvent.press(screen.getByText('Cancel'));

  expect(onPress).not.toHaveBeenCalled(); // fails: called once
});
```

### Fix

In a test environment, both engines now swap each callback a disabled
`Pressable` was given for a no-op in its `testOnly_*` prop, so
testing-library stops at the button without running anything. Dropping
the prop instead makes testing-library fall back to handlers further up
the tree. For `PressableWithTouchable` those are the ones `Touchable`
gets, so a bare `fireEvent(button, 'pressIn')` throws reading `event.x`,
and a `pressIn` followed by `press` inside `hitSlop` still fires
`onPressIn` and `onPress` (see the review thread). The hover callbacks
are swapped too. Every platform masks hover on a disabled button
(`effectiveHover` is `isHovered && enabled` on Android, iOS/macOS and
web), and `StatefulPressable`'s hover gesture is `enabled: disabled !==
true`.

Callbacks that weren't given stay unset, as on an enabled button.
Testing-library then keeps looking further up the tree for them, as it
does on `main`, so pressing a disabled `Pressable` that has no `onPress`
still reaches an enabled `Pressable` or `Touchable` around it. As on
`main`, a bare `fireEvent(button, 'pressIn')` on a disabled `Pressable`
without `onPressIn` still throws.

Nothing changes outside a test environment or for an enabled
`Pressable`, so #4417 stays fixed. The handlers `Touchable` gets are
left alone on purpose: the native button still reports press-out and
hover-out when it gets disabled mid-press or mid-hover, and `Pressable`
needs them to reset `pressed` and call `onPressOut` / `onHoverOut`.

`LegacyPressable` has the same wiring, but `jestSetup.js` replaces it
with React Native's `Pressable`, which honours `disabled`, so I left it
alone. #3612 fixed the same kind of bug for the legacy buttons'
`enabled` prop.

## Test plan

- Added a regression test to `src/__tests__/mocks.test.tsx` that runs on
both engines. It calls each `testOnly_*` handler of a disabled
`Pressable` without an event, the way a bare `fireEvent(button,
'pressIn')` does, and checks that nothing throws and none of the
callbacks fire. It also checks that a disabled `Pressable` without
callbacks leaves the `testOnly_*` props unset. It fails on `main`, where
the user's callbacks fire, and passes with this change. Like #4416, it
checks the props instead of calling `fireEvent`, because this repo pins
`@testing-library/react-native@12.9`, and that version doesn't look up
`testOnly_*` props.
- Ran a throwaway suite (not committed) against
`@testing-library/react-native` 13.3.3 and 14.1.0 on both engines,
mapped in through a scratch Jest config. For a disabled `Pressable`
given all six callbacks, it covers bare `fireEvent` calls with `press`,
`pressIn`, `pressOut`, `longPress` and `hoverOut`, a `pressIn` followed
by `press` with an event (with and without `hitSlop`), `hoverIn` with an
event, `fireEvent.press` on the button and on a child `Text`,
`userEvent.press` and `userEvent.longPress`:
  - On `main`, every one of them fires the matching callbacks.
  - With this change none of them fires anything or throws.
- On an enabled `Pressable`, `fireEvent.press` and `userEvent.press`
still fire the callbacks.
- On `PressableWithTouchable`, native `buttonPressOut` /
`buttonHoverOut` events dispatched after it gets disabled mid-press /
mid-hover still call `onPressOut` / `onHoverOut` and reset `pressed`.
- Ran a second throwaway suite on 12.9, 13.3.3 and 14.1.0 with a
disabled `Pressable` (both engines) inside an enabled `Pressable` or
`Touchable`. It covers `fireEvent.press` on the inner button and on its
`Text`, a bare `fireEvent(button, 'pressIn')`, and `userEvent.press`:
- With callbacks of its own, nothing fires on 13.3.3 and 14.1.0. On
`main` the inner callbacks fire.
- Without callbacks, every case behaves as on `main`, including the
enclosing `onPress` firing where it did before.
  - On 12.9 every case behaves as on `main`.
- In `packages/react-native-gesture-handler`:
  - `yarn test`: 26 suites, 258 tests pass.
  - `yarn ts-check`: clean.
- `yarn lint:js`: 0 errors and no warnings in the touched files. The
Prettier check is clean.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fireEvent(element, 'press') is a no-op on a relation-free Pressable since 3.2.0

3 participants