Skip to content

Extremely slow test performance with userEvent.type - things to look for for a cause? #977

Answered by ph-fritsche
joeattardi asked this question in Q&A
Discussion options

You must be logged in to vote

I don't see any obvious cause for the major difference in performance.

The two APIs might seem similar, but they are not.
With fireEvent.change you dispatch a change event. Simple and fast.
With userEvent.type you simulate a user clicking on an element and pressing keys on the keyboard. A lot happens and this might lead to a change event, but it probably doesn't.

By using user-event you trade performance for accuracy. You remove the risk that assumptions in your test - e.g. that a change event will be dispatched - might be wrong and something else might break your component. (See the blog post linked above on how easy it is to be wrong about such a basic assumption.)
You remove the need…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@joeattardi
Comment options

Answer selected by joeattardi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants