Description
Describe the Feature
RTL has userEvent
that simulates user interactions instead of just dispatching native events like fireEvent
.
Possible Implementations
In RTL this is a separate package, as it can be used with various web TL implementations based on DOM TL. We could just add it to our main package as another export.
Alternatively, we could migrate our repo to monorepo and have it as a separate package.
Features
Example APIs
- simulate typing events, by inputing text character by character and also triggering
onFocus
/onBlur
- simulate scroll events which involve following native calls:
onScrollBeginDrag
,onScrollEndDrag
and also in between values. - simulate pasteboard event
In the initial PR we should focus on mobile features for touch screen devices, while later on we might add also more keyboard control/pointer events that make sense for connected accessories/desktop platforms like mac/windows
API surface
User Event has two versions of API, legacy v13, and current v14. I think that unless we find any compelling reasons, we should try to maintain API similarity with current v14.
Defining correct approach
In order to define correct behaviour person implementing this would have to start with investigating the real RN app behaviour on both iOS and Android. In order to observe what should happen e.g. when calling userEvent.press
they would have to attach all potentially relevant event handlers for given host component, and observe sequence of called events as well as passed payloads. In certain cases there would be slight differences between iOS and Android, which might need further consideration.
Using fireEvent
Unlike the original User Event we do not have access to simulated DOM env that would dispatch events for us, in such case we will probably want to use fireEvent
under-the-hood to trigger a sequence of relevant events for us.
Related Issues
This issue is inspired by #1114 by @AugustinLF