-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Labels
Missing infoMissing reproPlatform: AndroidThis issue is specific to AndroidThis issue is specific to Android
Description
Description
Passing enable={false}
to a RectButton
will have no effect when running jest tests.
My guess is that since RectButton
is using TouchableNativeFeedback
(
react-native-gesture-handler/src/mocks.ts
Line 34 in f0868f7
const RectButton = TouchableNativeFeedback; |
disabled
instead, it has no effect.
A potential fix could be:
import React from 'react';
import { Pressable } from 'react-native';
import type { RectButtonProperties } from 'react-native-gesture-handler';
const RectButtonMock = (props: RectButtonProperties) => {
const { onPress, enabled, ...rest } = props;
return (
<Pressable
disabled={!enabled}
onPress={() => onPress && onPress(true)}
{...rest}
>
{props.children}
</Pressable>
);
};
jest.mock('react-native-gesture-handler', () => {
const actual = jest.requireActual('react-native-gesture-handler');
return {
...actual,
RectButton: RectButtonMock,
};
});
Steps to reproduce
describe.only('Testing disabled Button', () => {
it('onPress does not trigger', function () {
const onPress = jest.fn();
const { getByTestId } = render(
<RectButton testID="btn" onPress={onPress} enabled={false} />
);
const btn = getByTestId('btn');
expect(onPress).not.toHaveBeenCalled();
fireEvent.press(btn);
expect(onPress).not.toHaveBeenCalled(); // Will fail
});
});
Snack or a link to a repository
NA
Gesture Handler version
2.8.0
React Native version
0.70.5
Platforms
Android
JavaScript runtime
Hermes
Workflow
None
Architecture
None
Build type
None
Device
None
Device model
No response
Acknowledgements
Yes
asuetin
Metadata
Metadata
Assignees
Labels
Missing infoMissing reproPlatform: AndroidThis issue is specific to AndroidThis issue is specific to Android