Skip to content

Commit

Permalink
Replace await waitFor(() => getBy*) with await findBy*
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanjenningz committed Oct 1, 2022
1 parent 36855fb commit cefee5e
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions __tests__/pages/exercises/[lessonSlug].test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { render, waitFor, screen, fireEvent } from '@testing-library/react'
import { render, screen, fireEvent } from '@testing-library/react'
import '@testing-library/jest-dom'
import Exercises from '../../../pages/exercises/[lessonSlug]'
import { useRouter } from 'next/router'
Expand Down Expand Up @@ -28,9 +28,7 @@ describe('Exercises page', () => {
</MockedProvider>
)

await waitFor(() =>
screen.getByRole('heading', { name: /Foundations of JavaScript/i })
)
await screen.findByRole('heading', { name: /Foundations of JavaScript/i })

screen.getByRole('link', { name: 'CHALLENGES' })
screen.getByRole('link', { name: 'EXERCISES' })
Expand Down Expand Up @@ -66,15 +64,13 @@ describe('Exercises page', () => {
}
]

const { getByRole, queryByRole, getByLabelText } = render(
const { getByRole, findByRole, queryByRole, getByLabelText } = render(
<MockedProvider mocks={mocks} addTypename={false}>
<Exercises />
</MockedProvider>
)

await waitFor(() =>
getByRole('heading', { name: /Foundations of JavaScript/i })
)
await findByRole('heading', { name: /Foundations of JavaScript/i })

const solveExercisesButton = getByRole('button', {
name: 'SOLVE EXERCISES'
Expand Down Expand Up @@ -242,9 +238,7 @@ describe('Exercises page', () => {
</MockedProvider>
)

await waitFor(() =>
screen.getByRole('heading', { name: /Foundations of JavaScript/i })
)
await screen.findByRole('heading', { name: /Foundations of JavaScript/i })

screen.getByRole('link', { name: 'CHALLENGES' })
screen.getByRole('link', { name: 'EXERCISES' })
Expand All @@ -270,7 +264,7 @@ describe('Exercises page', () => {
</MockedProvider>
)

await waitFor(() => screen.getByRole('heading', { name: /500 Error/i }))
await screen.findByRole('heading', { name: /500 Error/i })
})

test('Should render a 404 error page if the lesson is not found', async () => {
Expand All @@ -292,7 +286,7 @@ describe('Exercises page', () => {
</MockedProvider>
)

await waitFor(() => screen.getByRole('heading', { name: /404 Error/i }))
await screen.findByRole('heading', { name: /404 Error/i })
})

test('Should render a loading spinner if useRouter is not ready', async () => {
Expand All @@ -314,6 +308,6 @@ describe('Exercises page', () => {
</MockedProvider>
)

await waitFor(() => screen.getByText('Loading...'))
await screen.findByText('Loading...')
})
})

0 comments on commit cefee5e

Please sign in to comment.