-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
ESLint: Fix testing-library/no-render-in-setup
violations
#45097
Conversation
Open in CodeSandbox Web Editor | VS Code | VS Code Insiders |
Size Change: 0 B Total Size: 1.27 MB ℹ️ View Unchanged
|
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, @tyxla!
I personally prefer inlining, but it would be great to hear feedback from others as well.
P.S. I think this rule was inspired by the Avoid Nesting when you're Testing post.
|
||
test( 'should render correctly', () => { | ||
renderVisibleTooltip(); |
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.
Nitty, but I usually prefer to have the render
call inlined into each test for better readability (and in case we needed to grab anything from return value of the render call).
Maybe we could extract a VisibleTooltip
React component, and then refactor each test to:
render( <VisibleTooltip /> );
@Mamaduka , is that also what you were referring to?
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.
Correct, and I like your suggestion of extracting this into a new component on the test module level.
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.
That sounds like an improvement, I'm happy to follow-up with this.
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.
Suggested in #45105. Thanks for the feedback, both 🙌
What?
This PR fixes all violations of the
testing-library/no-render-in-setup
rule, in preparation for enablingeslint-plugin-testing-library
globally for the project.See the plugin README for more info on the
testing-library
ESLint plugin.Why?
We've been improving our tests a lot recently with the migration to
@testing-library
. One way we could improve them is to better standardize them and follow best practices whenever we can, and one of the best ways to get there is to follow the recommended ESLint rules of the libraries and utilities we use under the hood.How?
We're moving the rendering to the actual tests.
Testing Instructions
Verify all checks are green.
cc @brookewp as we've been discussing working to address some of those violations together.