@@ -10,24 +10,24 @@ title: Queries
10
10
11
11
### getBy
12
12
13
- [ ` getBy* ` ] ( #query-apis ) queries returns the first matching node for a query, and
14
- throw an error if no elements match.
13
+ ` getBy* ` queries returns the first matching node for a query, and throws an
14
+ error if no elements match.
15
15
16
16
### getAllBy
17
17
18
- [ ` getAllBy* ` ] ( #queryall-and-getall-apis ) queries return an array of all matching
19
- nodes for a query, and throw an error if no elements match.
18
+ ` getAllBy* ` queries return an array of all matching nodes for a query, and
19
+ throws an error if no elements match.
20
20
21
21
### queryBy
22
22
23
- [ ` queryBy* ` ] ( #query-apis ) queries returns the first matching node for a query,
24
- and return ` null ` if no elements match.
23
+ ` queryBy* ` queries returns the first matching node for a query, and return
24
+ ` null ` if no elements match. This is useful for asserting an element is not
25
+ present.
25
26
26
27
### queryAllBy
27
28
28
- [ ` queryAllBy* ` ] ( #queryall-and-getall-apis ) queries return an array of all
29
- matching nodes for a query, and return an empty array (` [] ` ) if no elements
30
- match.
29
+ ` queryAllBy* ` queries return an array of all matching nodes for a query, and
30
+ return an empty array (` [] ` ) if no elements match.
31
31
32
32
## Options
33
33
@@ -709,30 +709,3 @@ getByText(container, (content, element) => {
709
709
return element .tagName .toLowerCase () === ' span' && content .startsWith (' Hello' )
710
710
})
711
711
```
712
-
713
- ## ` query ` APIs
714
-
715
- Each of the ` get ` APIs listed in the [ queries] ( #queries ) section above have a
716
- complimentary ` query ` API. The ` get ` APIs will throw errors if a proper node
717
- cannot be found. This is normally the desired effect. However, if you want to
718
- make an assertion that an element is _ not_ present in the DOM, then you can use
719
- the ` query ` API instead:
720
-
721
- ``` javascript
722
- const submitButton = queryByText (container, ' submit' )
723
- expect (submitButton).toBeNull () // it doesn't exist
724
- // or if you're using the custom matchers:
725
- expect (submitButton).not .toBeTruthy ()
726
- ```
727
-
728
- ## ` queryAll ` and ` getAll ` APIs
729
-
730
- Each of the ` query ` APIs have a corresponsing ` queryAll ` version that always
731
- returns an Array of matching nodes. ` getAll ` is the same but throws when the
732
- array has a length of 0.
733
-
734
- ``` javascript
735
- const submitButtons = queryAllByText (container, ' submit' )
736
- expect (submitButtons).toHaveLength (3 ) // expect 3 elements
737
- expect (submitButtons[0 ]).toBeTruthy ()
738
- ```
0 commit comments