@@ -11,7 +11,7 @@ See the following sections for a detailed breakdown of the test
1111``` jsx
1212// __tests__/fetch.test.js
1313import React from ' react'
14- import { render , fireEvent , waitForElement , screen } from ' @testing-library/react'
14+ import { render , fireEvent , waitFor , screen } from ' @testing-library/react'
1515import ' @testing-library/jest-dom/extend-expect'
1616import axiosMock from ' axios'
1717import Fetch from ' ../fetch'
@@ -28,7 +28,7 @@ test('loads and displays greeting', async () => {
2828
2929 fireEvent .click (screen .getByText (' Load Greeting' ))
3030
31- await waitForElement (() => screen .getByRole (' heading' ))
31+ await waitFor (() => screen .getByRole (' heading' ))
3232
3333 expect (axiosMock .get ).toHaveBeenCalledTimes (1 )
3434 expect (axiosMock .get ).toHaveBeenCalledWith (url)
@@ -48,7 +48,7 @@ test('loads and displays greeting', async () => {
4848import React from ' react'
4949
5050// import react-testing methods
51- import { render , fireEvent , waitForElement , screen } from ' @testing-library/react'
51+ import { render , fireEvent , waitFor , screen } from ' @testing-library/react'
5252
5353// add custom jest matchers from jest-dom
5454import ' @testing-library/jest-dom/extend-expect'
@@ -91,9 +91,9 @@ fireEvent.click(getByText('Load Greeting'))
9191
9292// Wait until the mocked `get` request promise resolves and
9393// the component calls setState and re-renders.
94- // `waitForElement ` waits until the callback doesn't throw an error
94+ // `waitFor ` waits until the callback doesn't throw an error
9595
96- await waitForElement (() =>
96+ await waitFor (() =>
9797 // getByRole throws an error if it cannot find an element
9898 screen .getByRole (' heading' )
9999)
0 commit comments