Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

findByRole with name option does not consider element title when element contains text. #274

Open
linuspahl opened this issue Feb 22, 2024 · 0 comments

Comments

@linuspahl
Copy link

linuspahl commented Feb 22, 2024

  • cypress-testing-library version: 10.0.1
  • node version: 21.1.0
  • yarn version: 1.22.19

Problem description:

I want to test the following button

<button title="button title">
  button text
</button>

In our unit tests (@testing-library/react 14.2.1) we can find the button with
screen.findByRole('button', { name: /button title/i })

The same query does not work in our e2e tests (@testing-library/cypress):
cy.findByRole('button', { name: /button title/i })

Usually I would not define a title for the button and use the following query:
cy.findByRole('button', { name: /button text/i })

But in my case the button contains just an icon (ligature), which is just a string in the DOM and it would be more appropriate to use the button title for the query, instead of this string.

As a workaround I am using cy.findByTitle(/button title/i).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant