Skip to content

Latest commit

 

History

History
19 lines (15 loc) · 655 Bytes

fireEvent-vs-userEvent.md

File metadata and controls

19 lines (15 loc) · 655 Bytes

fireEvent() vs userEvent

React Testing Library provides a function called fireEvent() to fire an event. For example:

fireEvent.change(input, { target: { value: 'hello world' } });

However, you should prefer methods provided by the package @testing-library/user-event over fireEvent(). While userEvent is built on top of fireEvent(), it provides methods that simulate user interactions more closely. For example userEvent.type() in the example below will trigger keyDown, keyPress, and keyUp events for each character which is much closer to the user's actual interactions.

userEvent.type(input, 'hello world');