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

fix: ignore getBy inside of within for prefer-presence-queries on absence queries #716

Conversation

nathanmmiller
Copy link
Contributor

Checks

Changes

  • Ignore getBy* nodes inside of within() for prefer-presence-queries when checking absence queries

Context

Fixes #518 [Well, partially fixes it.]

Copy link
Member

@Belco90 Belco90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @nathanmmiller! Thanks for your PR. I left a comment asking for more tests, since I think your implementation is not covering all cases as expected.

@@ -837,6 +837,9 @@ ruleTester.run(RULE_NAME, rule, {
// right after clicking submit button it disappears
expect(submitButton).not.toBeInTheDocument()
`,
`// checking absence on getBy* inside a within with queryBy* outside the within
expect(within(screen.getByRole("button")).queryByText("Hello")).not.toBeInTheDocument()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add another test to check that chained queries from within are reported as expected tho?

expect(within(screen.getByRole("button")).getByText("Hello")).not.toBeInTheDocument()

The example above should be reported, but I don't think it will be by your implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. I think maybe I need to rethink the way I am handling this - it's not sufficient to say "ignore everything inside a within." Lemme rethink and re-PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I think this does correctly handle this use case. I've added the unit test as requested and will re-raise the PR - it correctly deals with this exact case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Belco90 reopened at #717, with the additional test case

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

Successfully merging this pull request may close these issues.

False positives with testing-library/prefer-presence-queries
2 participants