Skip to content
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

[Chip] Fix onPress #3129

Merged
merged 3 commits into from
Jul 15, 2021
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
8 changes: 5 additions & 3 deletions src/Chip/Chip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ export const Chip: RneFunctionComponent<ChipProps> = ({
titleStyle,
])}
buttonStyle={StyleSheet.flatten([{ borderRadius: 30 }, buttonStyle])}
{...(onPress === undefined && {
TouchableComponent: TouchableWithoutFeedback,
})}
{...(onPress === undefined
? {
TouchableComponent: TouchableWithoutFeedback,
}
: { onPress })}
{...rest}
/>
);
Expand Down
8 changes: 8 additions & 0 deletions src/Chip/__tests__/Chip.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { Chip } from '../index';
import { renderWithTheme } from '../../../.ci/testHelper';
import { fireEvent } from '@testing-library/react-native';

describe('Chip Component', () => {
it('should render without issues', () => {
Expand All @@ -20,4 +21,11 @@ describe('Chip Component', () => {
expect(queryByText(type)).not.toBeNull();
expect(toJSON()).toMatchSnapshot();
});

it('should pass the onPress function when specified', () => {
const handlePress = jest.fn();
const { getByA11yRole } = renderWithTheme(<Chip onPress={handlePress} />);
fireEvent(getByA11yRole('button'), 'press');
expect(handlePress).toHaveBeenCalledTimes(1);
});
});