Skip to content

Commit 4ab0689

Browse files
committed
docs(prefer-in-document): add explanation for using .toHaveLength matcher with *AllBy* query
1 parent c1bd08a commit 4ab0689

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

docs/rules/prefer-in-document.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
This rule enforces checking existance of DOM nodes using `.toBeInTheDocument()`.
1212
The rule prefers that matcher over various existance checks such as `.toHaveLength(1)`, `.not.toBeNull()` and
1313
similar.
14+
However it's considered OK to use `.toHaveLength(value)` matcher with `*AllBy*` queries.
1415

1516
Examples of **incorrect** code for this rule:
1617

@@ -46,7 +47,7 @@ expect(screen.getByText("foo").length).toBe(1);
4647
expect(screen.queryByText("foo")).toBeInTheDocument();
4748
expect(await screen.findByText("foo")).toBeInTheDocument();
4849
expect(queryByText("foo")).toBeInTheDocument();
49-
expect(wrapper.queryAllByTestId("foo")).toBeInTheDocument();
50+
expect(wrapper.queryAllByTestId("foo")).toHaveLength(1);
5051
expect(screen.getAllByLabel("foo-bar")).toHaveLength(2);
5152
expect(notAQuery("foo-bar")).toHaveLength(1);
5253

0 commit comments

Comments
 (0)