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

Inconsistent guidance regarding selectors #5582

Open
dctalbot opened this issue Dec 18, 2023 · 0 comments
Open

Inconsistent guidance regarding selectors #5582

dctalbot opened this issue Dec 18, 2023 · 0 comments

Comments

@dctalbot
Copy link

dctalbot commented Dec 18, 2023

Subject

guides

Description

The Selecting Elements section in Best Practices contradicts the react testing library guide
even though the same doc claims says

our philosophy aligns closely with Testing Library's ethos and approach to writing tests. We strongly endorse their best practices.

I feel that the current guidance to suggest using data- testing attributes is bad and diminishes the value of tests by disregarding semantic HTML. See the link to RTL for more reasons. If a user is clicking a link, it should be an a tag (not a button or anything else), and the test should enforce that.

In the table of example selectors, one of the best options is cy.get('button').contains('Submit').click(), but this example is missing from the table.

The strategy to take here also depends on how much control/ownership a team has over the UI they are testing against. Some teams can afford to be looser or tighter with the selectivity depending on their organizational structure. Another factor to consider is what types of unit/integration tests are supporting their cypress e2e tests. I was disappointed to see the approach recommended without providing this context, and I think this section should be revised. I would offer to lend a hand, but it is an opinionated guide that needs to be authored by a core contributor IMO.

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

No branches or pull requests

1 participant