Repository navigation
testing library prefer user event
title: "Fix Guide — testing-library/prefer-user-event" type: fix-guide domain: frontend framework: react testing: "vitest + @testing-library/react" lint-rule: "testing-library/prefer-user-event" severity: warning tags: [testing-library, lint, react, vitest] created: 2026-07-14
Using fireEvent.change() and fireEvent.blur() in React Testing Library tests triggers the testing-library/prefer-user-event lint warning. fireEvent dispatches raw DOM events without simulating the full browser event sequence.
Replace fireEvent calls with @testing-library/user-event methods.
Instantiate userEvent at the top of your test or describe block:
import userEvent from '@testing-library/user-event';
const user = userEvent.setup();| Before | After |
|---|---|
fireEvent.change(selectEl, { target: { value: 'X' } }) |
await user.selectOptions(selectEl, 'X') |
fireEvent.blur(element) |
await user.tab() |
All userEvent methods return promises — every call requires await.
import userEvent from '@testing-library/user-event';
// Before
fireEvent.change(districtComboBox, { target: { value: 'DKM' } });
fireEvent.blur(districtComboBox);
// After
await user.selectOptions(districtComboBox, 'DKM');
await user.tab();Pros:
- Simulates real user interactions more accurately
- Fires the full browser event sequence (focus, keydown, input, keyup, etc.)
- Recommended by Testing Library maintainers
Cons:
- Requires
awaiton every call (minor verbosity) - Slightly different behavior than
fireEvent— some tests may need adjustment
-
Carbon Button
type="submit":userEvent.clickon a CarbonButtonwithtype="submit"does not trigger the parent form'sonSubmithandler. UsefireEvent.submit(formElement)directly instead. See Test Patterns — Formula Create Screen for details.
This wiki documents NR Waste Plus for users and developers. Verify security and deployment guidance against the current application configuration before applying it elsewhere.
- Report an issue or ask a question in the GitHub repository.
- Follow the Contributing Guidelines to propose an update.
- Read the Code of Conduct.
Collection indexes support human browsing and machine retrieval. Keep both current when adding or moving wiki pages.
NR Waste Plus Wiki | GitHub Repository