Skip to content

Commit 6de78e0

Browse files
authored
Merge pull request #55 from alexkrolick/pr/find-by
docs: add `findBy` query type docs.
2 parents 2b800cf + 4ccf988 commit 6de78e0

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

docs/api-queries.md

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,26 @@ present.
2626

2727
### queryAllBy
2828

29-
`queryAllBy*`queries return an array of all matching nodes for a query, and
29+
`queryAllBy*` queries return an array of all matching nodes for a query, and
3030
return an empty array (`[]`) if no elements match.
3131

32+
### findBy
33+
34+
`findBy*` queries return a promise which resolves when an element is found which
35+
matches the given query. The promise is rejected if no element is found after
36+
a default timeout of `4500`ms.
37+
38+
> Note, this is a simple combination of `getBy*` queries and
39+
> [`waitForElement`](/docs/api-async#waitforelement). The `findBy*` queries
40+
> accept the `waitForElement` options as the last argument. (i.e.
41+
> `findByText(container, 'text', queryOptions, waitForElementOptions)`)
42+
43+
### findAllBy
44+
45+
`findAllBy*` queries return a promise which resolves to an array of elements when
46+
any elements are found which match the given query. The promise is rejected if no
47+
elements are found after a default timeout of `4500`ms.
48+
3249
## Options
3350

3451
The argument to a query can be a _string_, _regular expression_, or _function_.
@@ -41,6 +58,7 @@ See [TextMatch](#textmatch) for documentation on what can be passed to a query.
4158
### `ByLabelText`
4259

4360
> getByLabelText, queryByLabelText, getAllByLabelText, queryAllByLabelText
61+
> findByLabelText, findAllByLabelText
4462
4563
```typescript
4664
getByLabelText(
@@ -128,7 +146,7 @@ const inputNode = getByLabelText(container, 'username', {
128146
### `ByPlaceholderText`
129147

130148
> getByPlaceholderText, queryByPlaceholderText, getAllByPlaceholderText,
131-
> queryAllByPlaceholderText
149+
> queryAllByPlaceholderText, findByPlaceholderText, findAllByPlaceholderText
132150
133151
```typescript
134152
getByPlaceholderText(
@@ -182,7 +200,7 @@ cy.getByPlaceholderText('Username').should('exist')
182200
183201
### `ByText`
184202

185-
> getByText, queryByText, getAllByText, queryAllByText
203+
> getByText, queryByText, getAllByText, queryAllByText, findByText, findAllByText
186204
187205
```typescript
188206
getByText(
@@ -253,7 +271,8 @@ If you'd rather disable this behavior, set `ignore` to `false`.
253271

254272
### `ByAltText`
255273

256-
> getByAltText, queryByAltText, getAllByAltText, queryAllByAltText
274+
> getByAltText, queryByAltText, getAllByAltText, queryAllByAltText, findByAltText,
275+
> findAllByAltText
257276
258277
```typescript
259278
getByAltText(
@@ -308,7 +327,8 @@ cy.getByAltText(/incredibles.*png$/i).should('exist')
308327

309328
### `ByTitle`
310329

311-
> getByTitle, queryByTitle, getAllByTitle, queryAllByTitle
330+
> getByTitle, queryByTitle, getAllByTitle, queryAllByTitle, findByTitle,
331+
> findAllByTitle
312332
313333
```typescript
314334
getByTitle(
@@ -366,7 +386,7 @@ cy.getByTitle('Close').should('exist')
366386
### `ByDisplayValue`
367387

368388
> getByDisplayValue, queryByDisplayValue, getAllByDisplayValue,
369-
> queryAllByDisplayValue
389+
> queryAllByDisplayValue, findByDisplayValue, findAllByDisplayValue
370390
371391
```typescript
372392
getByDisplayValue(
@@ -501,7 +521,8 @@ cy.getByDisplayName('Alaska').should('exist')
501521

502522
### `ByRole`
503523

504-
> getByRole, queryByRole, getAllByRole, queryAllByRole
524+
> getByRole, queryByRole, getAllByRole, queryAllByRole, findByRole,
525+
> findAllByRole
505526
506527
```typescript
507528
getByRole(
@@ -550,7 +571,8 @@ cy.getByRole('dialog').should('exist')
550571

551572
### `ByTestId`
552573

553-
> getByTestId, queryByTestId, getAllByTestId, queryAllByTestId
574+
> getByTestId, queryByTestId, getAllByTestId, queryAllByTestId, findByTestId,
575+
> findAllByTestId
554576
555577
```typescript
556578
getByTestId(

0 commit comments

Comments
 (0)