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 <noreply@anthropic.com>
This commit is contained in:
@@ -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 userEvent from "@testing-library/user-event";
|
||||||
import {
|
import {
|
||||||
afterEach,
|
afterEach,
|
||||||
@@ -345,20 +345,27 @@ describe("AgentPanel fade-out", () => {
|
|||||||
|
|
||||||
const { container } = render(<AgentPanel />);
|
const { container } = render(<AgentPanel />);
|
||||||
|
|
||||||
// Wait for the agent entry to appear
|
// With fake timers active, waitFor's polling setInterval never fires.
|
||||||
await waitFor(() => {
|
// 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();
|
||||||
|
});
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
container.querySelector(
|
container.querySelector(
|
||||||
'[data-testid="agent-entry-73_remove_test:coder-1"]',
|
'[data-testid="agent-entry-73_remove_test:coder-1"]',
|
||||||
),
|
),
|
||||||
).toBeInTheDocument();
|
).toBeInTheDocument();
|
||||||
|
|
||||||
|
// Advance fake timers by 60 seconds inside act to flush React state updates
|
||||||
|
await act(async () => {
|
||||||
|
vi.advanceTimersByTime(60_000);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Advance timers by 60 seconds
|
|
||||||
vi.advanceTimersByTime(60_000);
|
|
||||||
|
|
||||||
// Entry should be removed
|
// Entry should be removed
|
||||||
await waitFor(() => {
|
|
||||||
expect(
|
expect(
|
||||||
container.querySelector(
|
container.querySelector(
|
||||||
'[data-testid="agent-entry-73_remove_test:coder-1"]',
|
'[data-testid="agent-entry-73_remove_test:coder-1"]',
|
||||||
@@ -366,5 +373,4 @@ describe("AgentPanel fade-out", () => {
|
|||||||
).not.toBeInTheDocument();
|
).not.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user