Skip to content

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

Description

@huextrat

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

  1. 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'].
  2. Add the test file from the repro link below.
  3. Run it.
  4. 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.
  5. 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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions