Skip to content

Add Imperative Gesture Handler Testing API#4309

Draft
coado wants to merge 2 commits into
mainfrom
@coado/jest-new-api
Draft

Add Imperative Gesture Handler Testing API#4309
coado wants to merge 2 commits into
mainfrom
@coado/jest-new-api

Conversation

@coado

@coado coado commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Description

The goal is to make gesture lifecycle tests easier to write when we want to assert application state after each gesture step, without requiring users to manually construct RNGH state events with state, oldState, or handlerTag.

Instead of this lower-level style:

fireGestureHandler(panGesture, [
  { oldState: State.UNDETERMINED, state: State.BEGAN },
  { oldState: State.BEGAN, state: State.ACTIVE },
  { oldState: State.ACTIVE, state: State.END },
]);

tests can now use imperative controller:

const gesture = createGestureController(panGesture);

gesture.begin();
expect(onBegin).toHaveBeenCalled();

gesture.activate();
expect(onActivate).toHaveBeenCalled();

gesture.update({ translationX: 50 });
expect(onUpdate).toHaveBeenCalledWith(
  expect.objectContaining({ translationX: 50 })
);

gesture.end();
expect(onFinalize).toHaveBeenCalledWith(
  expect.objectContaining({ canceled: false })
);

Test plan

Added tests using new API.

Copilot AI review requested due to automatic review settings July 9, 2026 14:43

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 introduces an imperative testing helper (createGestureController) to simplify gesture lifecycle testing in RNGH Jest utilities, enabling step-by-step state transitions and assertions without manually crafting low-level state/oldState events.

Changes:

  • Added createGestureController, GestureController, and GestureControllerEvent to drive gesture lifecycles imperatively in tests.
  • Exported the new controller API from src/jestUtils/index.ts.
  • Added Jest tests covering lifecycle sequencing, validation, testID resolution, and disabled-gesture behavior.

Reviewed changes

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

File Description
packages/react-native-gesture-handler/src/jestUtils/jestUtils.ts Adds the gesture controller implementation and public API surface.
packages/react-native-gesture-handler/src/jestUtils/index.ts Re-exports the controller types and factory function.
packages/react-native-gesture-handler/src/tests/gestureController.test.tsx Adds tests validating the new imperative controller behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/react-native-gesture-handler/src/jestUtils/jestUtils.ts
Comment thread packages/react-native-gesture-handler/src/jestUtils/jestUtils.ts
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.

2 participants