Skip to content

Log when fireEvent fails to fire an event #1717

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

Closed
soulfresh opened this issue Dec 17, 2024 · 4 comments · May be fixed by #1726
Closed

Log when fireEvent fails to fire an event #1717

soulfresh opened this issue Dec 17, 2024 · 4 comments · May be fixed by #1726

Comments

@soulfresh
Copy link

Describe the Feature

I couldn't find a feature request for this, so apologies if this has already been requested.

It would be hugely beneficial if fireEvent could be configured to log a warning if it is unable to perform the requested event. Unfortunately, I sometimes write tests that press on disabled buttons and spend a silly amount of time debugging why my tests aren't working. I usually end up debugging down into react-native-testing-library only to find that I'm a dummy and my button has a disabled prop or some other attribute preventing the button event from firing. I would be a huge time saver if react-native-testing-library could give me a hint when I do dumb things like this.

Possible Implementations

One possibility might be to allow passing an additional debug param to fireEvent that when true will console log why fireEvent didn't work. It would be especially helpful to know what prop is preventing events from firing.

Another option that could work but isn't backwards compatible would be to return an object from fireEvent when it fails to fire an event.

Related Issues

N/A

@mdjastrzebski
Copy link
Member

That's a genuinely interesting idea. I will explore how to make it in our API, in a user-friendly way.

@mdjastrzebski
Copy link
Member

@soulfresh I am currently prototyping this feature, so far I've got that kind of warnings:

Informing about disabled event handlers.

 ▲ FireEvent: "focus" event handler is disabled on <TextInput editable={false} testID="subject" /> ("editable" prop).

It can be due to number of reasons:

  • "editable" prop - on TextInput
  • "pointerEvents" prop - on self or parent
  • "not a touch responder"

Additionally there is second type of warning:

 ▲ FireEvent: no enabled event handler for "submitEditing" found on <TextInput editable={false} testID="subject" /> or its ancestors.

This happens when there was no event handler triggered by fireEvent call. In case there is a disabled event handler found, but not enable both of these messages will be displayed.

What do you think about such messages?

@soulfresh
Copy link
Author

Thank you for working on this! Your messages seem intuitive to me 👍

I'm trying to remember exactly what disabling props I needed help with when I've run into issues in the past. I believe I was always trying to press on a button. Most likely it was accessibilityState={{disabled: true}}. I think your messaging would have been a huge help.

@mdjastrzebski
Copy link
Member

Replaced by #1718

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 a pull request may close this issue.

2 participants