is a companion library for Testing Library that simulates user interactions by
dispatching the events that would happen if the interaction took place in a browser.
These docs describe
email@example.com. This is still a pre-release and might be subject to breaking changes if they should be deemed necessary in the light of feedback we receive for this version. All planned breaking changes are already implemented though.
If you are starting or actively working on a project, we recommend to use this pre-release, as it includes important bug fixes and new features.
You can find the docs for
While most examples with
user-event are for
React, the library can be used
with any framework as long as there is a DOM.
fireEvent is a
utility to easier dispatch events.
It dispatches exactly the events you tell it to and just those - even if those exact events never had been dispatched in a real interaction in a browser.
user-event on the other hand dispatches the events like they would happen if a
user interacted with the document.
That might lead to the same events you previously dispatched per
directly, but it also might catch bugs that make it impossible for a user to
trigger said events.
This is why you should use
to test interaction with your components.
Writing tests with
We recommend to use
userEvent.setup() when rendering your component
and inline that rendering and setup in your test or use a setup function.
We discourage rendering or using any
userEvent functions outside of the test
itself - e.g. in a
after hook - for reasons described in
"Avoid Nesting When You're Testing".