-
Notifications
You must be signed in to change notification settings - Fork 145
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
feature request: new rule; no-render-in-setup #207
Comments
Possibly. I've been quite busy lately not sure when I can get to it. I'd someone else wants it that'd be awesome |
👋 I'm interested in picking this up. Ok if I assign myself @Belco90 ? |
@alessbell Sure! That'd be amazing, thanks ✨ |
🎉 This issue has been resolved in version 3.5.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
What is the rationale for this rule? |
https://kentcdodds.com/blog/avoid-nesting-when-youre-testing (We should add this to the rule's doc) |
@Belco90 Thanks for getting back so fast. Not sure I share Kent's concern, but I'm glad to have read it :). Obviously, I can just disable the rule if I want to. |
The author's explanation of the blog post linked above is almost uniquely expressed as a personal taste. This rule seems a bit too specific to be applied by default as an error, given that the error message and associated doc doesn't mention the cause for such a rule. let me submit a pull request about this =) |
Your example is a badly coded example. There is no rule that can prevent badly written tests like your case.
We all agree that in your example, it should all be in one test. But just because you have this one-off case of a badly written test suite doesn't mean there should be a rule to prevent using |
I agree with everything in this sentiment. In addition, the author states:
but this is just badly written code to begin with. What about the common case where no variable is assigned to?
I see no reason this shouldn't be allowed. It just seems like we are taking away from the entire intent of the existence of the |
Some rules prevent actual errors, others are recommendations. This rule won't prevent an actual error, it's just considered a best practice. The example illustrated is a common scenario. It's true that there could be a better example. However, it doesn't matter if you need to reset the component between tests, or pass several props or none at all. The recommendation is to avoid abstractions in tests to make it simple to follow and maintain. If you don't agree with the explanation given, or you found a scenario in your codebase to allow this pattern, it's as simple as turning off the rule. |
imo, it would be nice to have a rule that doesn't allow the usage of
render
in setup functions (before, beforeEach, etc)Would also be nice to have the ability to configure custom render functions, we have one for renderWithContext for example.
I've seen people do code like this:
imo this should just be a single test. why render it N times when nothing is changing in the render?
The text was updated successfully, but these errors were encountered: