From 3b3104ba2c58c08ea9843d94b917367cbf3a6090 Mon Sep 17 00:00:00 2001 From: Dave Date: Mon, 23 Feb 2026 15:09:11 +0000 Subject: [PATCH] fix: use act instead of waitFor in fake-timer test for agent fade-out waitFor's internal polling setInterval is itself faked when vi.useFakeTimers() is active, causing it to hang indefinitely. Replace the affected assertions with act + multiple Promise.resolve() to flush React state updates, and a direct assertion after act+vi.advanceTimersByTime instead of a second waitFor. Co-Authored-By: Claude Sonnet 4.6 --- frontend/src/components/AgentPanel.test.tsx | 40 ++++++++++++--------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/frontend/src/components/AgentPanel.test.tsx b/frontend/src/components/AgentPanel.test.tsx index a388a80..bb404e1 100644 --- a/frontend/src/components/AgentPanel.test.tsx +++ b/frontend/src/components/AgentPanel.test.tsx @@ -1,4 +1,4 @@ -import { render, screen, waitFor } from "@testing-library/react"; +import { act, render, screen, waitFor } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import { afterEach, @@ -345,26 +345,32 @@ describe("AgentPanel fade-out", () => { const { container } = render(); - // Wait for the agent entry to appear - await waitFor(() => { - expect( - container.querySelector( - '[data-testid="agent-entry-73_remove_test:coder-1"]', - ), - ).toBeInTheDocument(); + // With fake timers active, waitFor's polling setInterval never fires. + // Use act to flush pending promises and React state updates instead. + await act(async () => { + await Promise.resolve(); + await Promise.resolve(); + await Promise.resolve(); + await Promise.resolve(); }); - // Advance timers by 60 seconds - vi.advanceTimersByTime(60_000); + expect( + container.querySelector( + '[data-testid="agent-entry-73_remove_test:coder-1"]', + ), + ).toBeInTheDocument(); + + // Advance fake timers by 60 seconds inside act to flush React state updates + await act(async () => { + vi.advanceTimersByTime(60_000); + }); // Entry should be removed - await waitFor(() => { - expect( - container.querySelector( - '[data-testid="agent-entry-73_remove_test:coder-1"]', - ), - ).not.toBeInTheDocument(); - }); + expect( + container.querySelector( + '[data-testid="agent-entry-73_remove_test:coder-1"]', + ), + ).not.toBeInTheDocument(); }); }); });