From 2082c86e0b6ab4e64c5374b0cc8d421b08e1e270 Mon Sep 17 00:00:00 2001 From: Florian Laabs Date: Sat, 24 Oct 2026 00:40:56 +0200 Subject: [PATCH] test: hold the DataView's first answer while checking the placeholders The failing data source answered after 20 ms; on a slow runner that was over before the placeholders were checked. The answer now waits until the test lets it through. Signed-off-by: Florian Laabs --- packages/parity/src/collections.test.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/parity/src/collections.test.ts b/packages/parity/src/collections.test.ts index c59b537..b2e4af5 100644 --- a/packages/parity/src/collections.test.ts +++ b/packages/parity/src/collections.test.ts @@ -15,9 +15,10 @@ import { el, frameworks, render } from './harness.js'; const servers = Array.from({ length: 23 }, (_, index) => `server-${String(index + 1).padStart(2, '0')}`); /** A paged source over the servers; `fail` makes the next request fail */ function serverSource() { - const state = { fail: false }; + // `gate`: the answers wait until the test opens it (instead of 20 ms) – for states while loading + const state = { fail: false, gate: undefined as Promise | undefined }; const getItems = vi.fn(async ({ page = 1, pageSize = 10, search = '' }: DataRequest) => { - await new Promise((done) => setTimeout(done, 20)); + await (state.gate ?? new Promise((done) => setTimeout(done, 20))); if (state.fail) throw new Error('offline'); const found = servers.filter((name) => name.includes(search)); return { items: found.slice((page - 1) * pageSize, page * pageSize), totalCount: found.length }; @@ -57,6 +58,9 @@ describe.each(frameworks)('%s', (framework) => { it('shows placeholders while the first page loads, an error with a retry button', async () => { const { source, state, getItems } = serverSource(); state.fail = true; + // The first answer waits – on a slow machine 20 ms were over before the placeholders were checked + let answer!: () => void; + state.gate = new Promise((done) => (answer = done)); await render( framework, el('DataView', { @@ -68,6 +72,8 @@ describe.each(frameworks)('%s', (framework) => { }) ); expect(screen.getByRole('list', { name: 'Server' })).toHaveAttribute('aria-busy', 'true'); + state.gate = undefined; + answer(); const alert = await screen.findByRole('alert'); expect(alert).toHaveTextContent('The data could not be loaded.'); state.fail = false;