Skip to content
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

Un-report react-test-renderer's findByType & findAllByType queries as async. #671

Closed
Mrblackey opened this issue Oct 8, 2022 · 9 comments
Assignees
Labels
enhancement New feature or request triage Pending to be triaged by a maintainer

Comments

@Mrblackey
Copy link

What rule do you want to change?

await-async-query

Does this change cause the rule to produce more or fewer warnings?

Fewer warnings

How will the change be implemented?

Check that given node does not end with 'ByType'.

Example code

const elements = root.findAllByType('div')

How does the current rule affect the code?

promise returned from `findAllByType` query must be handled

How will the new rule affect the code?

This rule will not be applied if the query ends with 'ByType'.

Anything else?

No response

Do you want to submit a pull request to change the rule?

Yes

@Mrblackey Mrblackey added enhancement New feature or request triage Pending to be triaged by a maintainer labels Oct 8, 2022
@Belco90
Copy link
Member

Belco90 commented Oct 9, 2022

Hi @Mrblackey! This false positive is related to the Aggressive Reporting feature. Have you checked the Troubleshooting section to find more about restricting this behavior?

@Belco90 Belco90 added the awaiting response Waiting for a reply from the OP label Oct 9, 2022
@Mrblackey
Copy link
Author

Hello.
This option requires us to maintain the custom queries in two places instead of one, or ditch Aggresive Reporting altogether, which I prefer not to.
How about adding a new shared setting: testing-library/ignore-custom-queries: ["ByType"]?

@Belco90
Copy link
Member

Belco90 commented Oct 9, 2022

This option requires us to maintain the custom queries in two places instead of one

How so?

or ditch Aggresive Reporting altogether

That's not necessary, you have granular control over modules and queries that would be reported without opting-out the Aggressive Reporting.

I don't have full context, but if you have a custom query, it should follow the same pattern as the built-in ones. That means that findBy* queries are async, and must be reported as such.

@Mrblackey
Copy link
Author

Mrblackey commented Oct 9, 2022

Assuming we have "findByIcon" query, we add

"settings": {
	"testing-library/custom-queries": [
		"findByIcon"
	]
}

which is reported when not awaited. This works, as now react-test-renderer's findByType is not being reported, while our custom query is. What if we are adding a new custom query tomorrow? Someone has to remember to add it also to the settings section, in order to opt-in this new query to the rule. Perhaps the other way around makes more sense? Maybe assume that each matching query is indeed subject to this rule, unless specifically specified otherwise?

@Belco90
Copy link
Member

Belco90 commented Oct 9, 2022

Oh, wait. I didn't realize that react-test-renderer has its own findByType and findByProps. That definitely shouldn't be reported by any rule in this plugin (i.e. if the "query" is coming from react-test-renderer then should be ignored).

I think that bit is clear. What I don't get is do you actually want to stop reporting a custom findBy* query, or the findByType from react-test-renderer?

Perhaps the other way around makes more sense? Maybe assume that each matching query is indeed subject to this rule, unless specifically specified otherwise?

That's definitely debatable. It could be interesting to be able to disable custom queries with a new option rather than indicating which ones to report (making sure both options can't be enabled at the same time). Happy to receive a PR for that.

@Mrblackey
Copy link
Author

Mrblackey commented Oct 11, 2022

I think that bit is clear. What I don't get is do you actually want to stop reporting a custom findBy* query, or the findByType from react-test-renderer?

Only the react-test-renderer ones.

That's definitely debatable. It could be interesting to be able to disable custom queries with a new option rather than indicating which ones to report (making sure both options can't be enabled at the same time). Happy to receive a PR for that.

So you're basically saying these are two separate things, right? Reports of react-test-renderer should be avoided even without this PR, right?

@Belco90
Copy link
Member

Belco90 commented Oct 11, 2022

So you're basically saying these are two separate things, right? Reports of react-test-renderer should be avoided even without this PR, right?

Yes. I've created #673 to stop reporting utils from react-test-renderer.

@Belco90
Copy link
Member

Belco90 commented Dec 23, 2022

Taking care of this one!

@Belco90
Copy link
Member

Belco90 commented Dec 26, 2022

Closing in favor of #673

@Belco90 Belco90 closed this as not planned Won't fix, can't repro, duplicate, stale Dec 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request triage Pending to be triaged by a maintainer
Projects
None yet
2 participants