Why does Testing Library prefer getByRole over test ids?
Model answer
Querying by role and accessible name checks what real users and assistive technology see, so tests break when the UI becomes inaccessible, not just when the markup changes. Test ids are a fallback when no better query exists.
Learn this topic
Testing React Apps with Vitest and React Testing Library in the course React.js Full Course: Beginner to Advanced.
Sign in to add your own answer.