-
Notifications
You must be signed in to change notification settings - Fork 147
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
Add rules from "Common mistakes with React Testing Library" #165
Comments
Hey Nick, thanks for bringing this discussion here! Indeed, there are some other common mistakes we can prevent. From your list of new rules:
About already implemented ones:
|
Alternatively, could we possibly extend/reuse/configure
I think the main issue would be that we'd need to keep this updated pretty frequently. It would be annoying to have an incorrect act recommendation just because some new API isn't in the whitelist. Is this still worth the effort?
I was thinking the logic would just error if there was more than one
👍
Is
I thought the blog was suggesting that this was bad practice either way, regardless of the API change. |
Mmm I'm not sure. This even looks like 2 different rules:
Yeah that's my concern. I think it would imply too much effort for having a brittle check.
I think implementing exactly this without the autofix is completely worth it. I've found tons of tests in the codebase of the company I work for with more than one expect within waitFor callback. This rule would have save lot of time and prevent some errors. In my opinion, this is the most important one from the list you shared and shouldn't be that complex to implement.
Not really. You can check in the rule description it says "Given the screen component does not expose utility methods such as rerender() or the container property, it is correct to use the render response in those scenarios." (this description could be improved tho) We had some discussion around that tho, and we even tried to prevent using We have some other interesting issues or comments around this:
You are absolutely right here, didn't think about this has been a good practice even before |
The wording of the heading in the article is a little misleading, it's more about advising you to use destructuring than to not use
I'm thinking of a new rule that would error on methods like |
Ok, to sum up what we got so far:
const setUp = () => render(<Foo />);
const utils = setUp(); 👆 this should throw an error
|
I think I can start with this one in the incoming days. We can track it on #133 |
Since we've agreed on the overall direction here, I'm closing this discussion and replacing it with some new issues and pull requests I'm listing below, along with the original issues from my original post.
I've also recommended |
Thanks for organizing these tickets and discussion @nickmccurdy ! |
Asking here, just not to create a new ticket: should we also make |
I believe the rationale of not including it by default was to make it easier for users that are still on a legacy version (where this new API doesn't exist yet). I'd be fine with changing this to assume people are using an up-to-date version of the library if we can reach an agreement though |
There are some great suggestions in Common mistakes with React Testing Library, a few of which we could probably check statically:
Already implemented but should maybe be enabled by default:
Related issues: #133 #134 #162
The text was updated successfully, but these errors were encountered: