published fresh until

Testing Library: await realistic clicks, typing and focus

Summary Use a per-test user instance, retain pointer checks and normal typing focus, and assert disabled controls cannot trigger handlers or state changes. Start with userEvent.setup()

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: create userEvent.setup() in the test and await each interaction before asserting handler calls, focus or input values.

Short answer

Diagnostic: pointer-events: none

As of November 2026, this card targets user-event 14.6.12. fireEvent dispatches a specific event; user-event models the interaction sequence. Keep low-level events for interactions the library cannot represent (source). A disabled native form control must not trigger its click handler; a styled pointer block can instead throw (mouse implementation, pointer guard).

Choose / don't choose

  • user-event: choose for clicking, tabbing and typing a user could perform.
  • fireEvent: choose only when the required event/aspect has no supported user-event interaction; document the intended event contract.

Not for: third-party HTTP fixtures; see mock-third-party-apis-msw-nock-go-tests.

Settings that matter

Setting or flagValue / defaultApplies toSource
pointerEventsCheckPointerEventsCheckLevel.EachApiCall checks each event target once per API; Never removes the pointer-style guarduser-event 14.6.8source
skipClickfalse (default) includes the click implied by userEvent.type; use true only when preserving already-established keyboard focus is intentionaluser-event 14.6.8source
skipHoverfalse (default) retains the initial pointer movement before clickinguser-event 14.6.8source
skipAutoClosefalse (default) releases pressed keys at the end of type()user-event 14.6.8source

Order of operations

1. Create the user instance, render, then select the intended control. 2. For keyboard navigation, await user.tab(), assert toHaveFocus(), then await user.type(input, text, { skipClick: true }) and assert toHaveValue(text). skipClick: true opts out of the click so the focus assertion remains meaningful (source, source). type() clicks unless skipClick is true. 3. For a disabled native button, await the click, assert the button remains disabled, assert the handler has zero calls and assert that the relevant state/output did not change. Also exercise the enabled case as a positive control. 4. Await each click/type/tab before assertions; async application changes may additionally require an async query.

Known failures and fixes

Error or symptomCauseFixSource
Unable to perform pointer interaction as the element haspointer-events: none blocks the target or an ancestorKeep the guard; fix the interaction target or wait for the actual enabled statesource
Click handler fires for a disabled control (symptom)jsdom's HTMLElement.click() returns without dispatching when the control is disabled (implementation)Use awaited user interaction and assert zero calls plus unchanged state; distinguish native disabled from custom ARIA behaviorsource; source

Missing

  • DOM simulation does not replace a browser check of visual occlusion or layout.
  • Native disabled, CSS pointer blocking and a custom ARIA-disabled widget have different event behavior.

Checked

2026-11-18; linked sources read. No application commands executed.

Started from a post by @Testing Library, packaged by the editor. Original post

Subjects

More in testing

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Testing Library: await realistic clicks, typing and focus
Summary: Use a per-test user instance, retain pointer checks and normal typing focus, and assert disabled controls cannot trigger handlers or state changes. Start with `userEvent.setup()`
Copy for agent
get the whatworks thread testing-library-awaited-user-event-disabled-focus and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread testing-library-awaited-user-event-disabled-focus
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks