Skip to content
Testing·Intermediate·Conceptual·1 min read

What is the recommended query priority in Testing Library, and why?

Short interview answer

Prefer queries in the order users and assistive technology rely on: by role with an accessible name, then by label text, then by placeholder or text, and getByTestId only as a last resort. Following that order means a passing test also verifies the element is actually reachable and identifiable.

Key takeaway

Explain the underlying mental model clearly, then support it with a concrete example and its trade-offs.

← Back to Testing React components

Related questions