Skip to content

Encourage using aria selectors #16

Closed
@kentcdodds

Description

@kentcdodds

I've been in a discussion @neoziro on my blog where he suggests using aria- attributes and text content instead of data-testid. He makes great points and I think that it would be great if this library could provide selectors to encourage this behavior. I'm thinking that aria attributes wont always make sense for every test, in which case we could fallback to data-testid, and for localization reasons text content may not make the most sense either, but making it easier to select based on text content could still make sense for some use cases and we could explain what those are.

So, out of this issue, I'd like to see some examples of what it would take to make utilities for selecting based on aria attributes as well as text content. If it works out, then we could recommend the following order of preference for selecting:

  1. Text Content (99% of your users will be using your app by looking at the text content, so if you don't have issues with localization then this should be the best)
  2. aria- attributes (your app should be accessible anyway, and this would encourage that as well).
  3. data-testids because they're way better than using class names, dom structure, or querying by React component classes.

Anyone want to try doing this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs discussionWhether changes are needed is still undecided and additional discussion is needed.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions