Skip to content

Commit 379db54

Browse files
Fix root view error for jest (#2491)
## Description This PR fixed a problem related to `HandlerName must be used as a descendant of GestureHandlerRootView. Otherwise the gestures will not be recognized. See https://docs.swmansion.com/react-native-gesture-handler/docs/installation for more details.` in jest. <!-- Description and motivation for this PR. In some project Include 'Fixes #<number>' if this is fixing some issue. --> ## Related issues [2488](#2488) ## Test plan tested locally on my project :)
1 parent 0aa200c commit 379db54

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/handlers/createHandler.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ export default function createHandler<
402402
}
403403

404404
render() {
405-
if (__DEV__ && !this.context) {
405+
if (__DEV__ && !this.context && !isJestEnv()) {
406406
throw new Error(
407407
name +
408408
' must be used as a descendant of GestureHandlerRootView. Otherwise the gestures will not be recognized. See https://docs.swmansion.com/react-native-gesture-handler/docs/installation for more details.'

src/handlers/gestures/GestureDetector.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ import { State } from '../../State';
3636
import { TouchEventType } from '../../TouchEventType';
3737
import { ComposedGesture } from './gestureComposition';
3838
import { ActionType } from '../../ActionType';
39-
import { isFabric, REACT_NATIVE_VERSION, tagMessage } from '../../utils';
39+
import {
40+
isFabric,
41+
isJestEnv,
42+
REACT_NATIVE_VERSION,
43+
tagMessage,
44+
} from '../../utils';
4045
import { getShadowNodeFromRef } from '../../getShadowNodeFromRef';
4146
import { Platform } from 'react-native';
4247
import type RNGestureHandlerModuleWeb from '../../RNGestureHandlerModule.web';
@@ -607,7 +612,7 @@ interface GestureDetectorState {
607612
}
608613
export const GestureDetector = (props: GestureDetectorProps) => {
609614
const rootViewContext = useContext(GestureHandlerRootViewContext);
610-
if (__DEV__ && !rootViewContext) {
615+
if (__DEV__ && !rootViewContext && !isJestEnv()) {
611616
throw new Error(
612617
'GestureDetector must be used as a descendant of GestureHandlerRootView. Otherwise the gestures will not be recognized. See https://docs.swmansion.com/react-native-gesture-handler/docs/installation for more details.'
613618
);

0 commit comments

Comments
 (0)