-
Notifications
You must be signed in to change notification settings - Fork 148
Create a rule to support enforcing getBy* for toBeVisible #728
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
Comments
Hi @CodingItWrong! Thanks for this suggestion, it makes sense to report IIRC adding this matcher to the |
thanks @Belco90 — with that encouragement, I will try making this change, and see if the test suite + trying it out locally in an app gives the behavior I'd expect. I'll shoot to open up a PR either way 👍 |
Update: based on feedback on #730, we would like to implement this as a new rule rather than extending |
Thanks @CodingItWrong! Let us now if we can assist you somehow. |
@Belco90 would you like me to edit this issue so that the title/description reflect the new plan? |
@Belco90 When you said in #730 (comment)
Are you thinking that there would be no options configured by default, and that folks would have to specifically configure If so, I sort of see the argument for that. But that would create a surprising difference with
Because of that, since Thoughts? |
Yes please, that would be great!
That was my idea indeed. I wanted to keep it simple and require some config from the user. We can leave some suggested config in the rule's doc. I like the idea you suggest and agree with your explanation, but I'd say such preferences are debatable. Additionally, we would have to worry about the user overriding vs extending the initial provided config, which would make the first iteration more complicated. |
OK thanks @Belco90, I'll proceed on that basis. |
@CodingItWrong Great, thanks! Keep in mind that my proposal was just my first idea. Feel free to repurpose the options or the implementation as you wish. |
Just a progress note on this: @obsoke and I are pairing on implementing this, and we made good progress today. We think we will have a PR open in the next few weeks. |
🎉 This issue has been resolved in version 5.11.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
🎉 This issue has been resolved in version 6.0.0-alpha.15 🎉 The release is available on: Your semantic-release bot 📦🚀 |
(this issue has been edited to reflect an updated intent; it was originally a proposal to change
prefer-presence-queries
)Name for new rule
prefer-query-matchers
Description of the new rule
The rule should somehow provide a way to enforce that
toBeVisible()
should always be called with agetBy*
query in place of aqueryBy*
. This works differently than theprefer-presence-queries
rule, because a negative there expects an element to not be present in the DOM. In my understandingnot.toBeVisible()
means "is present in the DOM but is not visible," and it fails if it receives a null: "received value must be an HTMLElement or an SVGElement".Rather than coding for this specific matcher only, we currently plan to provide a configurable rule where you can configure which matchers require
get
and which requirequery
.Testing Library feature
The
getBy*
andqueryBy*
queries. It is prompted by thetoBeVisible
matcher fromjest-dom
.Testing Library frameworks
getBy*
andqueryBy*
are in the Core API and so are not specific to any framework.What category of rule is this?
Other: a best-practice recommendation. It allows users to configure rules to enforce use of the queries that will produce the best failure messages.
Code Examples
For the following proposed options schema:
With the following code:
1 and 3 would produce errors, and 2 and 4 would not.
If instead the
query
value was changed:Then 2 and 4 would produce errors, and 1 and 3 would not.
Anything else?
We investigated handling this with the existing
prefer-presence-queries
rule, but since that rule has a presence/absence distinction and the motivating casetoBeVisible
does not, it is a better fit to handle it in its own standalone rule. That also allows users to configure handling for any number of matchers.Do you want to submit a pull request to change the rule?
Yes
The text was updated successfully, but these errors were encountered: