From a3ecc086d97e5750cbf56638d67fa4f5dc89ef2c Mon Sep 17 00:00:00 2001 From: dotta Date: Mon, 6 Apr 2026 21:47:17 -0500 Subject: [PATCH] test(ui): wait for async issue search results Co-Authored-By: Paperclip --- ui/src/components/IssuesList.test.tsx | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/ui/src/components/IssuesList.test.tsx b/ui/src/components/IssuesList.test.tsx index 817fa2cc..a8665118 100644 --- a/ui/src/components/IssuesList.test.tsx +++ b/ui/src/components/IssuesList.test.tsx @@ -101,6 +101,22 @@ async function flush() { }); } +async function waitForAssertion(assertion: () => void, attempts = 20) { + let lastError: unknown; + + for (let attempt = 0; attempt < attempts; attempt += 1) { + try { + assertion(); + return; + } catch (error) { + lastError = error; + await flush(); + } + } + + throw lastError; +} + function renderWithQueryClient(node: ReactNode, container: HTMLDivElement) { const root = createRoot(container); const queryClient = new QueryClient({ @@ -158,12 +174,11 @@ describe("IssuesList", () => { container, ); - await flush(); - await flush(); - - expect(mockIssuesApi.list).toHaveBeenCalledWith("company-1", { q: "server", projectId: undefined }); - expect(container.textContent).toContain("Server result"); - expect(container.textContent).not.toContain("Local issue"); + await waitForAssertion(() => { + expect(mockIssuesApi.list).toHaveBeenCalledWith("company-1", { q: "server", projectId: undefined }); + expect(container.textContent).toContain("Server result"); + expect(container.textContent).not.toContain("Local issue"); + }); act(() => { root.unmount();