October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk6 min

How to Test User Interactions in UI Components

Test component interactions from a user’s perspective: find an accessible control, perform a realistic action, and assert the visible result.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Test a component interaction by locating a control the way a user or assistive technology would, performing a realistic action, and asserting the visible result. In React, that usually means a semantic query from React Testing Library, an awaited user-event action, and an assertion against the rendered DOM—not a check of private state or component methods.

Start with the behavior a user can observe

Testing Library’s guiding principle is: “The more your tests resemble the way your software is used, the more confidence they can give you.” Its practical consequence is to test the rendered interface rather than coupling routine behavior tests to internal state, methods, or lifecycle details. A test should answer what a person can do and what changes on screen.

For example, if clicking a button submits a form, test that the expected confirmation appears or that the relevant visible state changes. Do not assert that an internal variable was set unless that internal detail is itself the behavior the test is intended to protect.

Write a React interaction test

For a typical React component, render it with the project’s test helper, create a user-event session, find the control by role and accessible name, perform the action, and assert the result. The example assumes the project already has React Testing Library and @testing-library/user-event configured.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
ASUS VT229H 22 Inch 1080P FHD IPS Touchscreen Monitor, HDMI, VGA
  • Multi-Touch Display: 21.5" Full HD with 10-point multi-touch capacity, suitable for any application that involves virtual keyboard or multi-touch functionality for business use
  • Wide Viewing Angles: Stunningly wide 178 viewing angles and vivid, colorful displays with IPS panel technology
  • Frameless Design: Frameless design makes it suitable for almost-seamless multi-display setups
  • Eye Care Technology: ASUS Eye Care technology with flicker-free backlighting and blue light filter to minimize eye fatigue during extended use
  • Flexible Connectivity Options: Flexible connectivity with HDMI and VGA ports for versatile device compatibility
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import SaveButton from './SaveButton'

test('shows confirmation after saving', async () => {
  const user = userEvent.setup()
  render(<SaveButton />)

  await user.click(screen.getByRole('button', { name: /save/i }))

  expect(screen.getByText(/saved successfully/i)).toBeInTheDocument()
})

The assertion concerns visible output. If the message is rendered only after an asynchronous operation, use an asynchronous query such as findByText rather than adding a fixed sleep:

await user.click(screen.getByRole('button', { name: /save/i }))
expect(await screen.findByText(/saved successfully/i)).toBeInTheDocument()

Use your project’s established render wrapper when components need providers, routing, or other application context; the interaction pattern remains the same.

Choose selectors that reflect the interface

Role and accessible name

Use getByRole for semantic controls such as buttons, links, and checkboxes. The accessible name distinguishes controls with the same role. A role query searches for elements exposed in the accessibility tree; if an intended control cannot be found this way, check its semantics and accessible name instead of immediately reaching for a brittle selector.

Rank #2
Sale
ASUS BE24ECSBT 24 Inch 1080P Touchscreen Computer Monitor, Webcam, USB-C
  • Full HD Frameless Display: 23.8-inch Full HD (1920 x 1080) frameless IPS panel with wide viewing angles
  • Multi-Touch Capability: 10-point multi-touch capacity delivers a smooth and intuitive touch experience
  • Extensive Connectivity Options: Extensive connectivity with USB-C with power delivery, HDMI, DisplayPort in and out for daisy-chain, Earphone jack and USB hub for the most flexibility
  • Ergonomic Design: Ergonomic design with +35 -5 tilt, 180 swivel, 90 pivot and 130mm height adjustments for a comfortable viewing experience
  • USB-C Power Delivery: USB-C port allows simple laptop docking for data transmission and video signal to the display, as well as up to 80W power delivery to the laptop via just one cable
screen.getByRole('button', { name: /continue/i })
screen.getByRole('checkbox', { name: /remember me/i })

Labels and text

For form fields, query by their associated label. For other visible content or simple controls, text queries can be appropriate. React Testing Library’s introduction describes locating form elements by label and buttons or links by text.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
screen.getByLabelText(/email address/i)

Test IDs as a fallback

A test ID can be useful when meaningful visible text or a label is impractical. Treat it as an escape hatch, not the default for an ordinary control a person operates: a test ID verifies a project-specific hook, while a role or label also reflects the interface’s user-facing semantics.

Use user-event for actions and fireEvent for deliberate low-level events

user-event models common user actions more closely than dispatching one low-level event. It performs the sequence involved in an action and checks constraints such as whether an element is visible and interactable. Create a session with userEvent.setup() before rendering, then await actions such as clicks or typing.

Rank #3
Sale
InnoView 15.6" Portable Monitor 60Hz Touchscreen 1080P 10-Point Touch Screen Monitor Portable with Protective Sleeve Built-in Stand, 1200:1 HDMI USB C Travel Monitors for Laptop, PC, Phone
  • [10-Point Touchscreen Portable Monitor]: Portable screen compatible with Windows and MacOS systems. You can get touch function for your laptop by connecting via single full-featured Type-C interface. 𝐍𝐎𝐓𝐄: For Type-C 3.1 DP ALT-MODE or Thunderbolt 3/4 ports, please use the included USB-C to USB-C cable for power, video and touch. For devices without these ports, please use HDMI+power cable+USB-A to USB-C cable(If not connected, there is no touch functionality)
  • [Get a Monitor Protective Sleeve]: The case is tailor-made for your portable laptop monitor, lightweight and durable, easy to carry, a perfect companion for your travel or daily commute, and can be easily put into your backpack. Adopts scratch-resistant and durable material, effectively reducing screen wear and tear and enhancing protection. Built-in 90° adjustable stand, multiple suitable viewing angles can be selected. Monitor arm can be used for more space-saving installation
  • [FHD IPS Portable Display]: 15.6 inch 1080P portable screen for laptop adopts a real reliable IPS screen with a viewing angle of 178°. Compared with 1000:1 of other monitors, the contrast ratio is upgraded to 1200:1, combined with HDR technology, providing richer and more vivid colors and images. With low blue light and flicker-free functions, it ensures that you will not be tired when watching for a long time
  • [Diverse and Durable Ports]: 2 full-function Type-C ports and 1 standard HDMI port, plug-in and unplug tested thousands of times, with wide compatibility and durability. Suitable for laptops, phones, tablets, PS, Xbox or Nintendo Switch. Brightness and volume can be quickly adjusted by upgraded 4-button or touch. NOTE: Some devices cannot support touch due to system protection. For example, PS3/4/5, Switch, X-box, Steam-Deck, Fire TV stick/cube and iPhone, iPad(It's NOT the monitor's problem)
  • [NOTE]: ① If the display brightness or volume is low, please use a 15W or higher power adapter. (Adapter not included in the accessories). ②Provide a 30-day return policy and 18-month warranty (excluding external force damage). ③If you have any concerns, please let us know (shown on the back of the monitor)

fireEvent is a lightweight wrapper around dispatchEvent. Use it when the event you need is not covered by user-event or when deliberately testing a specific low-level event is the point of the test. Do not substitute it for a realistic user action by default.

The user-event documentation describes the package as usable with any framework when a DOM is available; the interaction approach is not exclusive to React.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Wait for asynchronous UI changes without arbitrary delays

Queries differ in what they do when an element is absent. Choose one that matches the timing and expected presence:

Rank #4
Pisichen Touchscreen Monitor 27" 2K 100Hz Gaming Monitor, QHD 2560x1440 IPS PC Monitors, 10-Point Touch Screen Computer Monitors, with USB C HDMI DP Ports, Built-in Speakers
  • - 27 inch 2K high resolution display delivers sharp and detailed visuals for work and entertainment.
  • - Enjoy vibrant colors and wide viewing angles on the 2K resolution panel for an immersive experience.
  • - 100Hz refresh rate ensures smooth motion and reduced blur during gaming or fast paced content.
  • - Responsive touchscreen allows intuitive interaction directly on the screen for enhanced productivity. Ideal for creative tasks, presentations, and interactive applications.
  • - Versatile connectivity with HDMI, DisplayPort, and USB C ports for easy compatibility with various devices.
Query pattern Use it when Behavior when there is no match
getBy… The element should already exist. Throws if no matching element is found.
queryBy… You need to check that an element is absent, or handle a non-match without an exception. Returns null when there is no match.
findBy… The element should appear asynchronously. Retries while waiting for a match, then rejects if none appears.

Use waitFor when an assertion needs to be retried as asynchronous work completes, especially when there is not a single new element to locate with findBy. Await the resulting query or wait. Avoid arbitrary timeouts: they can slow tests and still fail to correspond to when the UI actually updates.

Choose a DOM test or a real-browser component test

A DOM-based component test and a browser-based component test address related but different questions. DOM-capable test environments are useful for interactions that can be exercised against a rendered DOM. Use a real browser context when the behavior under test depends on actual browser behavior and needs that fidelity.

Playwright’s component-testing documentation describes mounting components in a browser context and interacting through locators. Testing Library’s guidance supports user-centered tests but does not establish that DOM simulation or browser component testing is universally superior. Choose according to the behavior, existing framework setup, and the degree of browser fidelity the question requires.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
FYHXele 24 Inch Touchscreen Monitor, IPS FHD 1080P Touch PC Display, 100Hz, LED Backlit Multi-Touch Monitor, VESA, HDMI & VGA & USB Computer Touch Screen for Gaming, Business, Warehouse, Bar, Gym
  • High-resolution display: FYHXele 24 inch LED touch screen monitor has a resolution of FHD 1080P, bringing you amazing visual clarity. It is perfect for offices, meetings, multimedia entertainment, and games. The IPS display presents a 178° vision, you can get consistent colors no matter which angle.
  • Sensitive touch: 24 Inch touch screen monitor uses a 10-point sensitive touch to improve your work efficiency. You can sensitively control the computer with a capacitive pen or finger. Supports 180° horizontal flip of the screen to adjust the suitable angle for work, reduce the burden on the spine.
  • Smooth office and gaming experience: 24 inch touch screen monitor is a good helper for office, especially for illustrators, data analysts, teachers, etc., It is also an excellent gaming monitor. With a refresh rate of 100Hz, the display is smooth, and FreeSync eliminates the problem of stuttering and ghosting on the game screen.
  • Reduce blue light and personalization: 24 inch touch screen monitor reduces blue light, protects your eyes, and reduces eye fatigue. This allows you to process documents, watch movies or play games for a long time more comfortably. Support VESA design, including wall mounting. (3.94''x3.94''/ 100mm X 100 mm)
  • Multiple Ports: Equipped with HDMI port, DP port, USB port, you can connect multiple devices, improving your work efficiency and gaming fun. FYHXele monitor provides 24-hour professional after-sales service. Please get in touch with us if you find any damage, malfunction, or missing accessories.
  • Prefer a DOM test for ordinary component behavior that the DOM test environment can represent adequately.
  • Use browser component testing when the interaction depends on browser behavior that a DOM simulation cannot faithfully exercise.
  • Whichever environment you choose, locate controls through user-facing semantics where practical and assert the resulting interface.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Apply the same principle outside React

Testing Library supports framework wrappers for React, Angular, and Vue, and its user-event package can work with any framework when a DOM is available. Vue’s testing guide identifies @vue/test-utils as its official low-level component-testing library and recommends exercising component interactions as a user would. Follow the testing and rendering conventions of your framework, while keeping the core test focused on an accessible control, an action, and an observable result.

Troubleshoot common interaction-test failures

The role query cannot find the control

Check that the element has the expected semantic role and an accessible name, and that the rendered component is present in the test. A failed role query may point to an accessibility issue rather than merely a selector mismatch. For a form field, try its associated label; use a test ID only when a meaningful user-facing query is not practical.

The action fails or has no effect

Use an awaited user-event action and verify that the target is visible and interactable. Check that the test renders the component in the context it needs and that the test is querying the intended control. If you intentionally need an event unsupported by user-event, use fireEvent for that specific event.

The expected content appears later

Replace an immediate getBy… query with findBy… when the element appears after asynchronous work. Use waitFor for a retryable assertion that is not naturally expressed as finding one element. Do not paper over timing differences with a guessed sleep.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The test breaks after an internal refactor

Review whether it relies on private state, component methods, lifecycle details, or selectors tied to markup that users do not perceive. Prefer an assertion about the interface outcome and a role, accessible name, label, or visible text that represents the interaction.

Or skip the browser setup

For website screenshots rather than component interaction tests, ScreenshotNeo provides a screenshot API and MCP server. It is not a replacement for testing a component’s interaction, but it can capture a rendered page with one request:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo documentation for request options. Cookie banners, popups, and chat widgets are removed before the shot; bot checks, blank pages, and failed loads are never billed. Its MCP server lets AI agents take screenshots. The free plan includes 1,000 screenshots per month with no card, and paid plans start at $5 for 3,000. Sign up for free.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.