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.
This commit is contained in:
tgiachi 2026-11-12 15:41:47 +01:00
commit f447a11269

View file

@ -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 () => {