Skip to content

Can we have chaining for the element selectors?  #1188

@tw-anoopjadhav

Description

@tw-anoopjadhav

For eg .

const buttonInsideContainer = screen.getByTestId('container').getByRole('button', { name : 'Test Button'})

This strategy helps avoid a lot of errors due to the selector resulting in multiple elements. I found this strategy being used in playwright. It pretty easy to uniquely select a specific element.

Lets take an example -

suppose we have a button deep inside a container. currently we have to first get the container like -

const container = screen.getByTestId('container');

and then use this container to uniquely select the button.

getByRole(container, 'button', {name : 'Test Button'});

Imagine how simple it will to be if we have chaining.

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