Skip to content

Commit cb221de

Browse files
alexkrolickKent C. Dodds
authored and
Kent C. Dodds
committed
docs: copy in waitForElement docs (#73)
* Copy in waitForElement docs * Link out to source * Add waitForElement examples
1 parent b1b38b5 commit cb221de

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

README.md

+34
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ facilitate testing implementation details). Read more about this in
8686
* [`cleanup`](#cleanup)
8787
* [`Simulate`](#simulate)
8888
* [`wait`](#wait)
89+
* [`waitForElement`](#waitforelement)
8990
* [`fireEvent(node: HTMLElement, event: Event)`](#fireeventnode-htmlelement-event-event)
9091
* [`TextMatch`](#textmatch)
9192
* [`query` APIs](#query-apis)
@@ -373,6 +374,39 @@ The default `interval` is `50ms`. However it will run your callback immediately
373374
on the next tick of the event loop (in a `setTimeout`) before starting the
374375
intervals.
375376

377+
### `waitForElement`
378+
379+
See [dom-testing-library#waitForElement](https://github.com/kentcdodds/dom-testing-library#waitforelement)
380+
381+
```js
382+
await waitForElement(() => getByText('Search'))
383+
```
384+
385+
<details>
386+
<summary>
387+
Example
388+
</summary>
389+
390+
```diff
391+
test('should submit form when valid', async () => {
392+
const mockSubmit = jest.fn()
393+
const {
394+
container,
395+
getByLabelText,
396+
getByText
397+
} = render(<Form onSubmit={mockSubmit} />)
398+
const nameInput = getByLabelText('Name')
399+
nameInput.value = 'Chewbacca'
400+
Simulate.change(nameInput)
401+
+ // wait for button to appear and click it
402+
+ const submitButton = await waitForElement(() => getByText('Search'))
403+
+ Simulate.click(submitButton)
404+
+ expect(mockSubmit).toBeCalled()
405+
})
406+
```
407+
408+
</details>
409+
376410
### `fireEvent(node: HTMLElement, event: Event)`
377411

378412
Fire DOM events.

0 commit comments

Comments
 (0)