Skip to content

Add children to button mock#4054

Merged
m-bert merged 1 commit intomainfrom
@mbert/buttons-children-in-mocks
Apr 3, 2026
Merged

Add children to button mock#4054
m-bert merged 1 commit intomainfrom
@mbert/buttons-children-in-mocks

Conversation

@m-bert
Copy link
Copy Markdown
Collaborator

@m-bert m-bert commented Apr 3, 2026

Description

This PR ports #4048 behavior to our current setup.

Test plan

import {fireEvent, render} from '@testing-library/react-native';
import {Text} from 'react-native';
import {RectButton} from 'react-native-gesture-handler';

test('Trigger press by text', () => {
  const onPress = jest.fn();
  const {getByText} = render(
    <RectButton onPress={onPress}>
      <Text>Press Me</Text>
    </RectButton>,
  );

  fireEvent.press(getByText('Press Me'));

  expect(onPress).toHaveBeenCalled();
});

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the React Native Gesture Handler Jest button mocks so mocked button components can render their children, enabling tests to query and press buttons via nested text content (ported from #4048).

Changes:

  • Update the RawButton mock to accept children.
  • Render children inside the mocked TouchableNativeFeedback (fallback to an empty View when absent).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/react-native-gesture-handler/src/mocks/GestureButtons.tsx
@m-bert m-bert merged commit 72f2d3e into main Apr 3, 2026
6 checks passed
@m-bert m-bert deleted the @mbert/buttons-children-in-mocks branch April 3, 2026 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants