Skip to content

Mocks: fix button content missing#4048

Open
alpha0010 wants to merge 1 commit intosoftware-mansion:2.30-stablefrom
alpha0010:patch-2
Open

Mocks: fix button content missing#4048
alpha0010 wants to merge 1 commit intosoftware-mansion:2.30-stablefrom
alpha0010:patch-2

Conversation

@alpha0010
Copy link
Copy Markdown
Contributor

Description

Lacking button content in the provided mocks makes it impossible to write tests such as "is the button with 'foo' rendered" or "press the button with 'bar'".

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();
});

This makes it impossible for tests to target a button based on displayed elements.
Copy link
Copy Markdown
Contributor

@m-bert m-bert left a comment

Choose a reason for hiding this comment

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

Thank you for this PR ❤️

export const RawButton = ({ enabled, children, ...rest }: any) => (
<TouchableNativeFeedback disabled={enabled === false} {...rest}>
<View />
{children}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
{children}
{children ?? <View />}

Could we please keep View in case where children is undefined?

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.

2 participants