From cefee5ec751d8661d051da7c245a1fdfa2076ab6 Mon Sep 17 00:00:00 2001 From: Bryan Jennings Date: Sat, 1 Oct 2022 15:09:33 -0700 Subject: [PATCH] Replace await waitFor(() => getBy*) with await findBy* --- .../pages/exercises/[lessonSlug].test.js | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/__tests__/pages/exercises/[lessonSlug].test.js b/__tests__/pages/exercises/[lessonSlug].test.js index 203c24bcd..e7a17d734 100644 --- a/__tests__/pages/exercises/[lessonSlug].test.js +++ b/__tests__/pages/exercises/[lessonSlug].test.js @@ -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' @@ -28,9 +28,7 @@ describe('Exercises page', () => { ) - 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' }) @@ -66,15 +64,13 @@ describe('Exercises page', () => { } ] - const { getByRole, queryByRole, getByLabelText } = render( + const { getByRole, findByRole, queryByRole, getByLabelText } = render( ) - await waitFor(() => - getByRole('heading', { name: /Foundations of JavaScript/i }) - ) + await findByRole('heading', { name: /Foundations of JavaScript/i }) const solveExercisesButton = getByRole('button', { name: 'SOLVE EXERCISES' @@ -242,9 +238,7 @@ describe('Exercises page', () => { ) - 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' }) @@ -270,7 +264,7 @@ describe('Exercises page', () => { ) - 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 () => { @@ -292,7 +286,7 @@ describe('Exercises page', () => { ) - 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 () => { @@ -314,6 +308,6 @@ describe('Exercises page', () => { ) - await waitFor(() => screen.getByText('Loading...')) + await screen.findByText('Loading...') }) })