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

fireEvent seems to always trigger event (onPress on Pressable) #1674

Closed
gunnartorfis opened this issue Oct 8, 2024 · 2 comments
Closed

fireEvent seems to always trigger event (onPress on Pressable) #1674

gunnartorfis opened this issue Oct 8, 2024 · 2 comments

Comments

@gunnartorfis
Copy link

Describe the bug

This is essentially reopening #28 but this time for Pressable.

When onPress is not assigned to a Pressable, onPress is still called.

const MyButton: React.FC = () => {
  return (
    <Pressable />
  )
}
const onPress = jest.fn();

render(
  <MyButton
    onPresss={() => {
      console.log("This gets called, but shouldn't");
      onPress();
    }}
  />
);

fireEvent.press(screen.getByTestId("ListItemPressable"));
expect(onPress).toHaveBeenCalled();

Expected behavior

onPress should not be called.

Steps to Reproduce

The code above demonstrates how to reproduce this.

Versions

@testing-library/react-native: ^12.7.2 => 12.7.2
react-test-renderer: ^18.2.0 => 18.3.1
@mdjastrzebski
Copy link
Member

With the current implementation of FireEvent api this is not fixable without breaking massive amount of tests in production.

I recommend that you use UserEvent press api, which should work fine.

@gunnartorfis
Copy link
Author

gunnartorfis commented Oct 8, 2024

@mdjastrzebski awesome, that works! Thanks.

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

No branches or pull requests

2 participants