File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff 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
373374on the next tick of the event loop (in a ` setTimeout ` ) before starting the
374375intervals .
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
378412Fire DOM events .
You can’t perform that action at this time.
0 commit comments