A Testing Library query that throws or returns null is used against the kind of presence check it cannot serve
What it finds
getBy queries throw when the element is missing, so expect(getBy...).not.toBeInTheDocument() fails with the query's error instead of passing. queryBy returns null instead, so it is the query for absence, while getBy states presence more clearly than expect(queryBy...).toBeInTheDocument().
Reported are expect of a getBy query followed by a negated presence matcher, and of a queryBy query followed by a presence matcher that is not negated.
From the rule's source, query_presence_mismatch.rs.
import { screen } from "@testing-library/react";it("hides", () => { expect(screen.getByText("Menu")).not.toBeInTheDocument();tx0 reports: getByText throws when the element is missing expect(screen.queryByText("Menu")).not.toBeInTheDocument();}); Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/ts:query-presence-mismatch" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/ts:query-presence-mismatch] reason="..."tx0 explain tx0/ts:query-presence-mismatch shows the same in the terminal. Found a false positive? Report it.