react-native-testing-library icon indicating copy to clipboard operation
react-native-testing-library copied to clipboard

Make onPress more life-like

Open hontas opened this issue 3 years ago • 6 comments

Taking inspiration from user-event which tries to mimic the real event order when user interacts with an element.

Summary

fireEvent.press currently only invoke the onPress-handler, and this PR aim to make it more real-life-like by also invoking onPressIn, onPressOut and onFocus if possible (silently failing if there are no registered handlers).

Also adding fireEvent.longPress for convenience.

Test plan

Test added in fireEvent.test.js

Thoughts

One could discuss that this should be another method called tap or something else that map closer to user intent than to event handler name. Looking forward to hear your feedback.

hontas avatar Mar 01 '21 08:03 hontas

Removed the throwing behaviour from invokeEvent here: #691 That PR should be merged before this one :)

hontas avatar Mar 01 '21 11:03 hontas

Mind rebasing? :)

thymikee avatar Mar 02 '21 14:03 thymikee

@thymikee done :)

hontas avatar Mar 03 '21 13:03 hontas

Will this ever be merged? I need to be able to work with onFocus and I can't test it atm.

rarenatoe avatar Apr 07 '22 18:04 rarenatoe

@rarenatoe we'll take care of it, but have no timeline. In the meantime you can invoke fireEvent(element, 'onFocus') manually

thymikee avatar Apr 08 '22 08:04 thymikee

Long term, shouldn't we try to to either create native-user-event package, or at least export something specific for that in this library? I'm not sure that having a different behaviour between the web and native library when doing a simple fireEvent is the best.

AugustinLF avatar Apr 12 '22 09:04 AugustinLF

Closing in favour of #1119 which would be more organised approach that is also similar to RTL.

mdjastrzebski avatar Dec 30 '22 09:12 mdjastrzebski