Go back

You don’t need data-testid for testing

Why frequent use of data-testid signals accessibility problems, and how to test interfaces using roles and accessible names.

You don’t need data-testid for testing

In his article, Dominik Dorfmeister explains why the data-testid attribute is a sign of poor accessibility and interface problems.

The main point: if you need a testid for a test, the element is difficult to find the way a user would. Users (and screen readers) rely on roles, text, and accessible names, rather than data-testid.

👉 Instead, the author suggests:

  • finding elements by role (getByRole)
  • using accessible names (aria-label, text)
  • building UI that makes sense to assistive technologies as well as to the eye

data-testid is not inherently bad. But frequent use is a symptom: either of poor semantics or of an awkward UI.

💡 A good test is almost like a user scenario If a test reads like “find the button with the text Submit,” you are on the right track.

Read

Copied