From f447a1126914d95b87dfa98203ebc02cb731a804 Mon Sep 17 00:00:00 2001 From: tgiachi Date: Thu, 12 Nov 2026 15:41:47 +0100 Subject: [PATCH] fix(web): wait for the address in the search page test instead of assuming it The test read the address right after the Artists section appeared, but the address is updated by an effect a moment later. On a busy machine it failed in every full run and passed alone. Closes #80. --- web/src/pages/SearchPage.test.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 () => {