Skip to content
Design systems and accessibilityguide

How to test an icon button by its accessible name

By SkeuDesign Editorial Team1 min read

Answer in brief

Write an interaction test that finds the button by role and name, then checks the outcome a user would observe. This catches naming regressions when a graphic or tooltip changes.

Exercise a favorite toggle

With Testing Library, get the button by role button and name “Favorite”. Activate it, query for the same button with pressed set to true, then activate it again and check the false state. Keep the button name stable throughout this test.

Scope identical commands to the intended row

A list with ten star buttons may legitimately give each the name “Favorite”. Find the row for a particular item and query for its favorite toggle within that row. After activating it, verify that this row's state changed and the adjacent item's state stayed the same.

Sources

  1. [1] ByRole | Testing Library — Testing Library, accessed November 23, 2026

Frequently asked questions

Should the test look for the SVG path?

An SVG selector ties this behavior test to one drawing. A role-and-name query checks whether the intended control can be identified.