Skip to content

Add contains option to getByRole to allow filtering. #354

Closed
@jsphstls

Description

@jsphstls

Describe the feature you'd like:

I want to be able to select an option by the text that it contains, or improve documentation to make an existing strategy easier to find.

I use react-testing-library and cypress-testing-library.

Suggested implementation:

getByRole('option', { contains: 'Some Option' })

Describe alternatives you've considered:

Best:
getByText('Some Option', { selector: '[role=option]' })

Not best:

getAllByRole('option').filter(option =>
   checkOptionForText('Some Option') // not sure where to look
)

Teachability, Documentation, Adoption, Migration Strategy:

If a new option would not break anything. I realize that getByRole supports every role available. Some roles like navigation would be a bad case for this enhancement. Other roles such as link would be improved.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions