Skip to content

[jest] Fixing enabled prop in buttons #3612

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 15, 2025
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
25 changes: 22 additions & 3 deletions packages/react-native-gesture-handler/jestSetup.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
jest.mock('./src/RNGestureHandlerModule', () => require('./src/mocks'));
jest.mock('./src/RNGestureHandlerModule', () => require('./src/mocks/mocks'));
jest.mock('./src/components/GestureButtons', () => require('./src/mocks/mocks'));
jest.mock('./src/components/Pressable/Pressable', () => require('./src/mocks/Pressable'));


jest.mock('./lib/commonjs/RNGestureHandlerModule', () =>
require('./lib/commonjs/mocks')
require('./lib/commonjs/mocks/mocks')
);
jest.mock('./lib/commonjs/components/GestureButtons', () =>
require('./lib/commonjs/mocks/mocks')
);
jest.mock('./lib/commonjs/components/Pressable', () =>
require('./lib/commonjs/mocks/Pressable')
);


jest.mock('./lib/module/RNGestureHandlerModule', () =>
require('./lib/module/mocks')
require('./lib/module/mocks/mocks')
);
jest.mock('./lib/module/components/GestureButtons', () =>
require('./lib/module/mocks/mocks')
);
jest.mock('./lib/module/components/Pressable', () =>
require('./lib/module/mocks/Pressable')
);

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Mocks from '../mocks';
import Mocks from '../mocks/mocks';

export default {
...Mocks,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,28 @@ export interface RawButtonProps

/**
* 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_onPress?: Function | null;

/**
* 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_onPressIn?: Function | null;

/**
* 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_onPressOut?: Function | null;

/**
* 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_onLongPress?: Function | null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Pressable as default } from 'react-native';
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {
DrawerLayoutAndroid,
View,
} from 'react-native';
import { State } from './State';
import { Directions } from './Directions';
import { State } from '../State';
import { Directions } from '../Directions';

const NOOP = () => {
// Do nothing
Expand All @@ -31,14 +31,14 @@ const LongPressGestureHandler = View;
const PinchGestureHandler = View;
const RotationGestureHandler = View;
const FlingGestureHandler = View;
const RawButton = ({ enabled, ...rest }: any) => (
<TouchableNativeFeedback disabled={!enabled} {...rest}>
export const RawButton = ({ enabled, ...rest }: any) => (
<TouchableNativeFeedback disabled={enabled === false} {...rest}>
<View />
</TouchableNativeFeedback>
);
const BaseButton = RawButton;
const RectButton = RawButton;
const BorderlessButton = TouchableNativeFeedback;
export const BaseButton = RawButton;
export const RectButton = RawButton;
export const BorderlessButton = TouchableNativeFeedback;

export default {
TouchableHighlight,
Expand All @@ -57,10 +57,6 @@ export default {
PinchGestureHandler,
RotationGestureHandler,
FlingGestureHandler,
RawButton,
BaseButton,
RectButton,
BorderlessButton,
PanGestureHandler,
attachGestureHandler,
createGestureHandler,
Expand Down
Loading