You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey @fabiendem! Thanks for the suggestion, it's an interesting one. It would be great if you finally make some time and implement it yourself. I'll try to help as much as I can!
I think there is no similar constraint as the one you want to apply. There are others about "do not do X inside Y callback" but they won't work in the same way. I can suggest you check no-render-in-setup and render-result-naming-convention which are related to the render method so you can see how to work around that
You can find some contributing guidelines in this project that will lead you through some parts and point to a few utils. We have tons of utils you can take advantage of, like the isRenderUtil or the isRenderVariableDeclarator, so you don't need to manually look for render methods but rely on those utils.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This may be tricky to check tho. What if the developer is rendering the component in the beforeEach hook? This rule won't find any valid render within the tests so all acts could be potentially reported.
But even, we would want to detect any act before a render call.
We can start by detecting this in the same blocks. Then detect acts in the before* blocks as well.
Rules must not depend on each other, so we have to assume this scenario is possible.
We can start by detecting this in the same blocks. Then detect acts in the before* blocks as well.
LGTM! So this rule would report acts for the current criteria OR for acts called before a render within the test block (ignoring them if no render is found).
Rules must not depend on each other, so we have to assume this scenario is possible.
yeah definitely
LGTM! So this rule would report acts for the current criteria OR for acts called before a render within the test block (ignoring them if no render is found).
Make sure `no-unnecessary-act` detects unnecessary `act` called before the `render` method · Issue #551 · testing-library/eslint-plugin-testing-library
Activity
Belco90 commentedon Feb 18, 2022
Hey @fabiendem! Thanks for the suggestion, it's an interesting one. It would be great if you finally make some time and implement it yourself. I'll try to help as much as I can!
fabiendem commentedon Feb 18, 2022
@Belco90 cheers.
I use a lot of ESLint rules but I have never written one.
Thanks
Belco90 commentedon Feb 18, 2022
I see. Some resources to help you with this:
no-render-in-setup
andrender-result-naming-convention
which are related to therender
method so you can see how to work around thatisRenderUtil
or theisRenderVariableDeclarator
, so you don't need to manually look forrender
methods but rely on those utils.fabiendem commentedon Feb 18, 2022
Thank you 👍
stale commentedon Apr 19, 2022
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
fabiendem commentedon Apr 20, 2022
Feature is still relevant, I didn't have a chance to tackle it yet.
Belco90 commentedon Apr 20, 2022
This may be tricky to check tho. What if the developer is rendering the component in the
beforeEach
hook? This rule won't find any valid render within the tests so all acts could be potentially reported.fabiendem commentedon Apr 20, 2022
We have this rule in place: https://github.com/testing-library/eslint-plugin-testing-library/blob/main/docs/rules/no-render-in-setup.md
So this is not an issue for us. But surely not everyone will have this rule enabled.
But even, we would want to detect any
act
before arender
call.We can start by detecting this in the same blocks. Then detect
acts
in thebefore*
blocks as well.Belco90 commentedon Apr 20, 2022
Rules must not depend on each other, so we have to assume this scenario is possible.
LGTM! So this rule would report acts for the current criteria OR for acts called before a render within the test block (ignoring them if no render is found).
fabiendem commentedon Apr 20, 2022
yeah definitely
yeah seems legit