Skip to content

userEvent

In one line

userEvent simulates real user interactions (click, type, etc.) more realistically than fireEvent, with proper event sequences.

In simple words

userEvent is part of Testing Library. It simulates user interactions like clicking, typing, and hovering — but more realistically than the older fireEvent utility.

The difference: when a real user types 'hello' in a text box, it's not one event — it's a sequence: focus, keydown 'h', keyup 'h', input 'h', keydown 'e', keyup 'e', input 'e', and so on. fireEvent.change fires just one change event. userEvent.type fires the full realistic sequence.

This matters because some components respond to specific events (like keydown for shortcuts). Using userEvent ensures your tests trigger the same events a real user would, making them more realistic and less likely to miss bugs.

Always prefer userEvent over fireEvent when possible.

Example

javascript
// Prefer userEvent (realistic)
await userEvent.type(input, 'hello');
await userEvent.click(button);

// Over fireEvent (simplified)
fireEvent.change(input, { target: { value: 'hello' } });
fireEvent.click(button);

userEvent fires the full event sequence; fireEvent fires a single simplified event.

Related terms

Related Resources

Related Lessons

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary