You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Jest] Add opt-out for the GestureHandlerRootView check - #4660
GestureDetector throws in development when it is not rendered inside GestureHandlerRootView. This also happens under Jest, where the check is usually just noise, and the testing guide did not mention it.
This PR:
adds react-native-gesture-handler/jest-setup/disableRootViewCheck.js, an opt-in setup file that mocks useEnsureGestureHandlerRootView for both src and lib/module,
moves the existing Jest mocks to jest-setup/index.js and keeps jestSetup.js as a one-line re-export, so existing configs keep working,
extends the error message in test environments with a hint on how to fix or disable the check, linking to the new docs section,
documents it in the testing guide.
The check stays enabled by default, so tests that forget the root view still fail the same way they would on a device.
Packed the library with yarn pack and installed it in a Jest app with @testing-library/react-native, then rendered a GestureDetector without GestureHandlerRootView:
jestSetup.js only: test fails with the new error message.
jestSetup.js + jest-setup/disableRootViewCheck.js: test passes.
jest-setup + jest-setup/disableRootViewCheck.js: test passes.
jestSetup.js shim keeps working.
Errors.test.tsx passes, the existing assertions still match since the message starts with the original text.
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.
Summary
Summary by CodeRabbit
Bug Fixes
Improved Jest setup so gesture-handler components are mocked consistently across package builds.
Added Jest-specific guidance when a gesture detector is rendered without GestureHandlerRootView, with options to wrap the rendered tree or disable the check.
Documentation
Updated testing instructions with the recommended setup path and details on handling the root-view requirement in Jest.
The root-view check now uses a Jest-specific error message. The Jest setup centralizes module mocks and includes an optional setup file that disables the check. The testing guide describes how to wrap rendered trees or configure the optional setup file.
The root-view check uses a Jest-specific error message in test environments. Other environments retain the existing message.
Jest mocks and setup instructions packages/react-native-gesture-handler/jest-setup/*, packages/react-native-gesture-handler/jestSetup.js, packages/react-native-gesture-handler/package.json, packages/docs-gesture-handler/docs/guides/testing.mdx
The Jest setup centralizes mocks for source and compiled modules. An optional setup file mocks the root-view check with a no-op hook. The package includes the setup directory, and the guide explains how to use it or wrap rendered trees in GestureHandlerRootView.
Possibly related issues
software-mansion/react-native-gesture-handler#4657: The change adds an optional Jest setup that mocks the hook identified in this issue. It also documents wrapping rendered trees in GestureHandlerRootView.
The change is largely mergeable, but the documented Jest configuration should remove the invalid placeholder before users copy it.
Pre-merge checks: 3
Check name
Status
Explanation
Title check
The title "[Jest] Add opt-out for the GestureHandlerRootView check" matches the main change. The PR adds an opt-in Jest setup file, jest-setup/disableRootViewCheck.js, that mocks useEnsureGestureHan…
Linked Issues check
The PR satisfies the coding requirements in [#4657]. The testing guide documents wrapping rendered trees in GestureHandlerRootView and provides the opt-in jest-setup/disableRootViewCheck.js setup.…
Out of Scope Changes check
The changes stay within [#4657]. The setup files, package inclusion, compatibility re-export, test-environment error hint, and testing-guide update all address the Jest root-view failure or its docume…
Full details: Title check
Explanation
The title "[Jest] Add opt-out for the GestureHandlerRootView check" matches the main change. The PR adds an opt-in Jest setup file, jest-setup/disableRootViewCheck.js, that mocks useEnsureGestureHandlerRootView. The title names the Jest scope and the opt-out behavior. It does not mention the moved mocks in jest-setup/index.js or the documentation update, which is expected for a title.
Full details: Linked Issues check
Explanation
The PR satisfies the coding requirements in [#4657]. The testing guide documents wrapping rendered trees in GestureHandlerRootView and provides the opt-in jest-setup/disableRootViewCheck.js setup. The setup mocks useEnsureGestureHandlerRootView for src and lib/module. jestSetup.js remains compatible through its re-export. The root-view check remains enabled by default.
Full details: Out of Scope Changes check
Explanation
The changes stay within [#4657]. The setup files, package inclusion, compatibility re-export, test-environment error hint, and testing-guide update all address the Jest root-view failure or its documented workaround. No unrelated change is established by the reviewed summary.
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Warning
Some tools did not complete. Review the errors below.
ESLint
If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.
Parsing error: ESLint was configured to run on <tsconfigRootDir>/packages/docs-gesture-handler/docs/guides/testing.mdx using parserOptions.project: /tsconfig.json
The extension for the file (.mdx) is non-standard. You should add parserOptions.extraFileExtensions to your config.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
GestureDetectorthrows in development when it is not rendered insideGestureHandlerRootView. This also happens under Jest, where the check is usually just noise, and the testing guide did not mention it.This PR:
react-native-gesture-handler/jest-setup/disableRootViewCheck.js, an opt-in setup file that mocksuseEnsureGestureHandlerRootViewfor bothsrcandlib/module,jest-setup/index.jsand keepsjestSetup.jsas a one-line re-export, so existing configs keep working,The check stays enabled by default, so tests that forget the root view still fail the same way they would on a device.
Fixes #4657
Test plan
Packed the library with
yarn packand installed it in a Jest app with@testing-library/react-native, then rendered aGestureDetectorwithoutGestureHandlerRootView:jestSetup.jsonly: test fails with the new error message.jestSetup.js+jest-setup/disableRootViewCheck.js: test passes.jest-setup+jest-setup/disableRootViewCheck.js: test passes.jestSetup.jsshim keeps working.Errors.test.tsxpasses, the existing assertions still match since the message starts with the original text.