Skip to content

Add recognizer-aware Jest API#4307

Draft
coado wants to merge 5 commits into
mainfrom
@coado/jest-tests-3.1
Draft

Add recognizer-aware Jest API#4307
coado wants to merge 5 commits into
mainfrom
@coado/jest-tests-3.1

Conversation

@coado

@coado coado commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Description

Adds an experimental recognizer-aware Jest gesture simulation API:

  • introduces simulatePointerGesture for feeding fake pointer streams into real JS/web recognizers instead of manually emitting gesture states,
  • supports gesture objects, gesture test IDs, detector hosts, and child views inside GestureDetector,
  • resolves detector/child targets to attached handler tags and runs all attached recognizers through the shared web orchestrator/arbitrator path,
  • supports Tap, Pan, LongPress, Fling, Pinch, and Rotation recognizers,
  • adds deterministic pointer timing via timeStepMs, hold timing via holdForMs, and multi-pointer paths via pointers,
  • updates the Jest HostGestureDetector mock and hook gesture registry so detector-based target resolution works in tests.

Test plan

Added new tests

Copilot AI review requested due to automatic review settings July 8, 2026 15:14

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 adds an experimental, recognizer-aware Jest gesture simulation helper for feeding synthetic pointer streams through real web/JS recognizers, and refactors the web orchestrator’s state arbitration into a shared, policy-driven core to support that path.

Changes:

  • Introduces simulatePointerGesture to drive real web gesture handlers in Jest (including resolving targets via v3 gestures, test IDs, and detector hosts).
  • Extracts platform-neutral arbitration logic into GestureArbitrator and updates the web GestureHandlerOrchestrator to delegate to it.
  • Improves v3 gesture typing (discriminated type) and centralizes the single-gesture union type.

Reviewed changes

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

Show a summary per file
File Description
packages/react-native-gesture-handler/src/web/tools/GestureHandlerOrchestrator.ts Delegates orchestration/arbitration to the new shared GestureArbitrator with a web relation policy.
packages/react-native-gesture-handler/src/v3/types/GestureTypes.ts Adds a generic TType to make SingleGesture.type discriminated.
packages/react-native-gesture-handler/src/v3/hooks/useGesture.ts Propagates the discriminated gesture type through useGesture generics.
packages/react-native-gesture-handler/src/v3/hooks/gestures/tap/useTapGesture.ts Specializes useGesture generics so Tap gestures narrow their type.
packages/react-native-gesture-handler/src/v3/hooks/gestures/tap/TapTypes.ts Updates Tap gesture type aliases to carry the discriminated type.
packages/react-native-gesture-handler/src/v3/hooks/gestures/singleGestureUnion.ts Introduces a shared AnySingleGesture union type for v3 single gestures.
packages/react-native-gesture-handler/src/v3/hooks/gestures/rotation/RotationTypes.ts Updates Rotation gesture type aliases to carry the discriminated type.
packages/react-native-gesture-handler/src/v3/hooks/gestures/pinch/PinchTypes.ts Updates Pinch gesture type aliases to carry the discriminated type.
packages/react-native-gesture-handler/src/v3/hooks/gestures/pan/usePanGesture.ts Specializes useGesture generics so Pan gestures narrow their type.
packages/react-native-gesture-handler/src/v3/hooks/gestures/pan/PanTypes.ts Updates Pan gesture type aliases to carry the discriminated type.
packages/react-native-gesture-handler/src/v3/hooks/gestures/native/NativeTypes.ts Updates Native gesture type aliases to carry the discriminated type.
packages/react-native-gesture-handler/src/v3/hooks/gestures/manual/ManualTypes.ts Updates Manual gesture type aliases to carry the discriminated type.
packages/react-native-gesture-handler/src/v3/hooks/gestures/longPress/useLongPressGesture.ts Specializes useGesture generics so LongPress gestures narrow their type.
packages/react-native-gesture-handler/src/v3/hooks/gestures/longPress/LongPressTypes.ts Updates LongPress gesture type aliases to carry the discriminated type.
packages/react-native-gesture-handler/src/v3/hooks/gestures/index.ts Re-exports the consolidated single-gesture union type from singleGestureUnion.ts.
packages/react-native-gesture-handler/src/v3/hooks/gestures/hover/HoverTypes.ts Updates Hover gesture type aliases to carry the discriminated type.
packages/react-native-gesture-handler/src/v3/hooks/gestures/fling/FlingTypes.ts Updates Fling gesture type aliases to carry the discriminated type.
packages/react-native-gesture-handler/src/mocks/hostDetector.tsx Enhances the Jest host detector mock typing to include handlerTags for detector-based resolution.
packages/react-native-gesture-handler/src/jestUtils/simulatePointerGesture.ts Adds the new recognizer-aware pointer gesture simulation utility for Jest.
packages/react-native-gesture-handler/src/jestUtils/index.ts Exposes simulatePointerGesture and its options from the Jest utils barrel.
packages/react-native-gesture-handler/src/handlers/handlersRegistry.ts Stores v3 hook gestures in test env to enable detector/testID resolution and narrowing.
packages/react-native-gesture-handler/src/handlers/gestureArbitration/GestureArbitrator.ts Adds the platform-neutral arbitration core (record/await/activate/cancel sequencing).
packages/react-native-gesture-handler/src/handlers/gestureArbitration/GestureArbitrationTypes.ts Defines the platform-neutral handler and relation-policy contracts.
packages/react-native-gesture-handler/src/tests/recognizerAwareGesture.test.tsx Adds Jest tests covering the new pointer simulation API and target resolution behaviors.
packages/react-native-gesture-handler/src/tests/GestureHandlerOrchestrator.test.ts Adds characterization tests for orchestrator/arbitration behavior (awaiting, cancellation, simultaneity).

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

Comment on lines +359 to +369
return pointers.map((pointer, index) => {
invariant(
pointer.path.length > 0,
'simulatePointerGesture() expected each pointer path to contain at least one point.'
);

return {
id: pointer.id ?? index + 1,
path: pointer.path,
};
});
Comment on lines +60 to +63
shouldBeginWithRecordedHandlers: (handler, recordedHandlers) =>
handler.shouldBeginWithRecordedHandlers(
recordedHandlers as IGestureHandler[]
),
const shouldBeCancelledBy = (otherHandler: IGestureHandler) => {
return this.shouldHandlerBeCancelledBy(handler, otherHandler);
};
// Private beacuse of Singleton
@coado coado changed the title @coado/jest tests 3.1 Add recognizer-aware Jest API Jul 9, 2026
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