TkDodo
Read post

Test IDs are an a11y smell

Using data-testid attributes in tests is an accessibility smell because users can't see or interact with test IDs. Role-based selectors (via Testing Library or Playwright) are superior because they mirror how real users interact with apps, catch inaccessible markup like clickable divs lacking semantic roles, and provide implicit a11y testing. If a role-based selector can't find an element, that's a signal the UI itself is inaccessible. Practical tips include using semantic HTML for implicit ARIA roles, associating form labels, using headings and landmarks, leveraging Testing Playground, and navigating with the keyboard to catch issues.

    #testing#html#accessibility
Mar 23•7m read time•From tkdodo.eu
Post cover image
Table of contents
Testing LibraryAccessibilityExampleRole-based selectorsContinue Series
136.8K Impressions1 Comment
TkDodo's image
TkDodo

TK Dodo is a platform dedicated to sharing insights and resources on software development, technolog...

184 Followers

•

1.4K Upvotes

Would you recommend this post?

Copy link
WhatsApp
Facebook
X
New Squad
  • © 2026 Daily Dev Ltd.
  • Guidelines
  • Explore
  • Tags
  • Sources
  • Squads
  • Leaderboard