Skip to content

jestSetup does not mock useEnsureGestureHandlerRootView, so v3 GestureDetector throws in Jest #4657

Closed

Description

@MrCordeiro

Description

After the Jest setup from the testing guide (jestSetup.js and transformIgnorePatterns), rendering a v3 GestureDetector fails with:

GestureDetector must be used as a descendant of GestureHandlerRootView. Otherwise the gestures will not be recognized.

useEnsureGestureHandlerRootView throws when DEV is true, there is no root view context, and Platform.OS !== 'web'. In Jest, DEV is true and Platform.OS is ios. jestSetup.js mocks HostGestureDetector but not this hook.

Expected: either jestSetup.js mocks the hook, or the testing guide says to wrap test renders in GestureHandlerRootView.

Steps to reproduce

  1. Install react-native-gesture-handler 3.3.0 in a project with Jest and @testing-library/react-native.
  2. Add import "react-native-gesture-handler/jestSetup" to the Jest setup file, as the guide says.
  3. Render this component in a test, with no GestureHandlerRootView around it:
import { View } from "react-native";
import { GestureDetector, usePanGesture } from "react-native-gesture-handler";
function Box() {
  const pan = usePanGesture({});
  return (
    <GestureDetector gesture={pan}>
      <View testID="box" />
    </GestureDetector>
  );
}

test("renders", async () => {
  await render(<Box />);
});
  1. The test throws the error above.

Workaround: mock react-native-gesture-handler/lib/module/v3/detectors/useEnsureGestureHandlerRootView to return { useEnsureGestureHandlerRootView: jest.fn() }.

A link to a Gist, an Expo Snack or a link to a repository based on this template that reproduces the bug.

https://gist.github.com/MrCordeiro/fa7519eda51b0254a8f36eb14e322003

Gesture Handler version

3.3.0

React Native version

0.88.1

Platforms

iOS

JavaScript runtime

None

Workflow

Using Expo Prebuild or an Expo development build

Build type

None

Device

None

Device model

No response

Acknowledgements

Yes

Activity

  1. m-bert commented on Nov 2, 2026

    @m-bert
    Collaborator

    Hi @MrCordeiro! can you confirm that approach from #4660 works in your case?

  2. MrCordeiro commented on Nov 2, 2026

    @MrCordeiro
    Author

    Hi @MrCordeiro! can you confirm that approach from #4660 works in your case?

    Hi @m-bert ! Just tested and it worked!

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

    Platform: iOSThis issue is specific to iOS

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions