Replies: 2 comments 3 replies
-
Hey @hovsater! First of all, we should probably improve the docs around this query so it's clear to everyone. You are right about using However, if the element is not found, you'll see a misleading error like "null isn't in the document" which is not really helpful. Using a Additionally, it also tries to encourage you to use the same type of queries for presence or absence for consistency. We could say that this part of the rule doesn't prevent an actual error, but enforces a good practice. |
Beta Was this translation helpful? Give feedback.
-
Really glad I found this question posted because I had the same concern. Basically, if the presence assertion fails, the |
Beta Was this translation helpful? Give feedback.
-
While I generally agree with the rules enforced by
prefer-presence-queries
, I'm having a hard time understanding why the following is an error.The rule clearly wants me to use
screen.getByText
here. Wouldn't that make thetoBeInTheDocument
matcher completely unnecessary? Ifscreen.getByText
error out, then the node was not found, there's no need for thetoBeInTheDocument
matcher at all. I might as well do (albeit making the assertion implicit rather than explicit).Personally, I use the
queryBy
versions for presence checks and thegetBy
versions for when I make assertions/actions on the node itself.Would love to hear the reasoning behind this. 🙂
Beta Was this translation helpful? Give feedback.
All reactions