diff --git a/web/src/pages/SearchPage.test.tsx b/web/src/pages/SearchPage.test.tsx index 70ae2aa..1dc2110 100644 --- a/web/src/pages/SearchPage.test.tsx +++ b/web/src/pages/SearchPage.test.tsx @@ -1,5 +1,5 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query' -import { fireEvent, render, screen, within } from '@testing-library/react' +import { fireEvent, render, screen, waitFor, within } from '@testing-library/react' import userEvent from '@testing-library/user-event' import { MemoryRouter, Route, Routes, useLocation } from 'react-router-dom' import { beforeEach, expect, test, vi } from 'vitest' @@ -134,10 +134,10 @@ test('the address follows what was typed', async () => { renderSearch() await userEvent.type(box(), 'bjork') await screen.findByRole('region', { name: 'Artists' }) - expect(screen.getByTestId('location')).toHaveTextContent('/search?q=bjork') + // The address is updated by an effect, a moment after the section appears: wait for it, do not assume it. + await waitFor(() => expect(screen.getByTestId('location')).toHaveTextContent('/search?q=bjork')) await userEvent.clear(box()) - await wait(350) - expect(screen.getByTestId('location')).toHaveTextContent(/^\/search$/) + await waitFor(() => expect(screen.getByTestId('location')).toHaveTextContent(/^\/search$/)) }) test('a search longer than the server accepts is cut to 200 characters', async () => {