Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions packages/react-native-gesture-handler/src/__tests__/mocks.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,51 @@ test('Pressable exposes its press handlers to testing-library', () => {
expect(button.props.testOnly_onPressOut).toBe(onPressOut);
expect(button.props.testOnly_onLongPress).toBe(onLongPress);
});

test('Pressable exposes its hover handlers to testing-library', () => {
const onHoverIn = jest.fn();
const onHoverOut = jest.fn();

render(
<GestureHandlerRootView>
<Pressable
testID="pressable"
onHoverIn={onHoverIn}
onHoverOut={onHoverOut}>
<Text>Hover Me</Text>
</Pressable>
</GestureHandlerRootView>
);

const button = screen.getByTestId('pressable');

expect(button.props.testOnly_onHoverIn).toBe(onHoverIn);
expect(button.props.testOnly_onHoverOut).toBe(onHoverOut);
});

test('StatefulPressable exposes its press and hover handlers to testing-library', () => {
// A relation prop routes `Pressable` to the `StatefulPressable` engine,
// which has to forward the same `testOnly_*` props as the default engine.
const onPress = jest.fn();
const onHoverIn = jest.fn();
const onHoverOut = jest.fn();

render(
<GestureHandlerRootView>
<Pressable
testID="pressable"
simultaneousWith={[]}
onPress={onPress}
onHoverIn={onHoverIn}
onHoverOut={onHoverOut}>
<Text>Press Me</Text>
</Pressable>
</GestureHandlerRootView>
);

const button = screen.getByTestId('pressable');

expect(button.props.testOnly_onPress).toBe(onPress);
expect(button.props.testOnly_onHoverIn).toBe(onHoverIn);
expect(button.props.testOnly_onHoverOut).toBe(onHoverOut);
});
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,20 @@ export interface LegacyRawButtonProps
*/
// eslint-disable-next-line @typescript-eslint/ban-types
testOnly_onLongPress?: Function | null | undefined;

/**
* Used for testing-library compatibility, not passed to the native component.
* @deprecated test-only props are deprecated and will be removed in the future.
*/
// eslint-disable-next-line @typescript-eslint/ban-types
testOnly_onHoverIn?: Function | null | undefined;

/**
* Used for testing-library compatibility, not passed to the native component.
* @deprecated test-only props are deprecated and will be removed in the future.
*/
// eslint-disable-next-line @typescript-eslint/ban-types
testOnly_onHoverOut?: Function | null | undefined;
}
interface ButtonWithRefProps {
innerRef?: React.Ref<React.ComponentType<any>> | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,20 @@ export interface ButtonProps extends ViewProps, AccessibilityProps {
*/
// eslint-disable-next-line @typescript-eslint/ban-types
testOnly_onLongPress?: Function | null | undefined;

/**
* Used for testing-library compatibility, not passed to the native component.
* @deprecated test-only props are deprecated and will be removed in the future.
*/
// eslint-disable-next-line @typescript-eslint/ban-types
testOnly_onHoverIn?: Function | null | undefined;

/**
* Used for testing-library compatibility, not passed to the native component.
* @deprecated test-only props are deprecated and will be removed in the future.
*/
// eslint-disable-next-line @typescript-eslint/ban-types
testOnly_onHoverOut?: Function | null | undefined;
}

export const ButtonComponent =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,9 @@ const LegacyPressable = (props: LegacyPressableProps) => {
testOnly_onPress={IS_TEST_ENV ? onPress : undefined}
testOnly_onPressIn={IS_TEST_ENV ? onPressIn : undefined}
testOnly_onPressOut={IS_TEST_ENV ? onPressOut : undefined}
testOnly_onLongPress={IS_TEST_ENV ? onLongPress : undefined}>
testOnly_onLongPress={IS_TEST_ENV ? onLongPress : undefined}
testOnly_onHoverIn={IS_TEST_ENV ? onHoverIn : undefined}
testOnly_onHoverOut={IS_TEST_ENV ? onHoverOut : undefined}>
{childrenProp}
{__DEV__ ? (
<PressabilityDebugView color="red" hitSlop={normalizedHitSlop} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,19 @@ export interface PressableProps extends CommonPressableProps {
* A gesture object or an array of gesture objects containing the configuration and callbacks to be
* used with the Pressable's gesture handlers.
*/
simultaneousWith?: AnyGesture;
simultaneousWith?: AnyGesture | AnyGesture[];

/**
* A gesture object or an array of gesture objects containing the configuration and callbacks to be
* used with the Pressable's gesture handlers.
*/
requireToFail?: AnyGesture;
requireToFail?: AnyGesture | AnyGesture[];

/**
* A gesture object or an array of gesture objects containing the configuration and callbacks to be
* used with the Pressable's gesture handlers.
*/
block?: AnyGesture;
block?: AnyGesture | AnyGesture[];
}

interface CommonPressableProps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,9 @@ const PressableWithTouchable = (props: PressableProps) => {
testOnly_onPress={IS_TEST_ENV ? onPress : undefined}
testOnly_onPressIn={IS_TEST_ENV ? onPressIn : undefined}
testOnly_onPressOut={IS_TEST_ENV ? onPressOut : undefined}
testOnly_onLongPress={IS_TEST_ENV ? onLongPress : undefined}>
testOnly_onLongPress={IS_TEST_ENV ? onLongPress : undefined}
testOnly_onHoverIn={IS_TEST_ENV ? onHoverIn : undefined}
testOnly_onHoverOut={IS_TEST_ENV ? onHoverOut : undefined}>
{resolvedChildren}
{__DEV__ ? (
<PressabilityDebugView color="red" hitSlop={normalizedHitSlop} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,9 @@ const StatefulPressable = (props: PressableProps) => {
testOnly_onPress={IS_TEST_ENV ? onPress : undefined}
testOnly_onPressIn={IS_TEST_ENV ? onPressIn : undefined}
testOnly_onPressOut={IS_TEST_ENV ? onPressOut : undefined}
testOnly_onLongPress={IS_TEST_ENV ? onLongPress : undefined}>
testOnly_onLongPress={IS_TEST_ENV ? onLongPress : undefined}
testOnly_onHoverIn={IS_TEST_ENV ? onHoverIn : undefined}
testOnly_onHoverOut={IS_TEST_ENV ? onHoverOut : undefined}>
{childrenProp}
{__DEV__ ? (
<PressabilityDebugView color="red" hitSlop={normalizedHitSlop} />
Expand Down
Loading