-
Notifications
You must be signed in to change notification settings - Fork 27.1k
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
Use recommended pattern in testing example #28404
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you update the corresponding example as well? Thank you!
@leerob will do! Are there any plans to incorporate the recommended linter(s) for Testing Library and Cypress, either as standalone dependencies in |
I like the idea of extending the default ESLint setup on the example to include this package! 👍 |
@leerob I added linting configuration and updated the example test. For clarity, I also swapped in the name "Home" for the tests, since the example is not testing the App but rather the |
Hey @htunnicliff, thank you for submitting this PR and updating the example! 💪🏼 |
@delbaoliveira from my end it looks like this PR is still marked as having "requested changes." Is there anything else I should do to help get this merged? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much!
Looking like linting is failing here, which is why it didn't auto merge. |
Since the official linter for testing library, `eslint-plugin-testing-library` recommends using `screen` to write queries, this MR updates the testing library example to follow the pattern recommended by the linter. > DOM Testing Library (and other Testing Library frameworks built on top of it) exports a screen object which has every query (and a debug method). This works better with autocomplete and makes each test a little simpler to write and maintain. > This rule aims to force writing tests using built-in queries directly from screen object rather than destructuring them from render result. Given the screen component does not expose utility methods such as rerender() or the container property, it is correct to use the render returned value in those scenarios. See the `prefer-screen-queries` rules docs for more info: https://github.com/testing-library/eslint-plugin-testing-library/blob/main/docs/rules/prefer-screen-queries.md
Since the official linter for React Testing Library (
eslint-plugin-testing-library
) recommends usingscreen
to write queries, this MR updates the Testing Library example to follow the pattern recommended by the linter.See the
prefer-screen-queries
rules docs for more info: https://github.com/testing-library/eslint-plugin-testing-library/blob/main/docs/rules/prefer-screen-queries.mdDocumentation / Examples