Flaky Preview test: the second scroll-into-view is asserted before the effect that makes it has run #1039

Closed
opened 2026-10-02 20:45:49 +00:00 by claude-bot · 1 comment
Collaborator

Seen

PR #1038 (no frontend change at all) went red on CI / Frontend (shard 2/2), run https://git.rhoving.com/rbrooks/Quest-Board/actions/runs/1801 (job 63083):

FAIL src/pages/table/Preview.test.jsx > Preview > coming into view (#1020) > is brought into view again when a fetched entry arrives and the panel has grown, and then no more
AssertionError: expected "vi.fn()" to be called 2 times, but got 1 times
 ❯ src/pages/table/Preview.test.jsx:197:22

1 failed, 1572 passed.

Cause (read from the code; not reproduced locally)

Preview.jsx brings the panel into view from a passive effect (useEffect(..., [kind, id, drawn])). The test does

expect(await screen.findByText("Blackfen adder")).toBeInTheDocument();
expect(scroll).toHaveBeenCalledTimes(2);

findByText resolves as soon as the text is in the DOM, which is at commit. A passive effect runs some time after the commit, so on a busy runner the synchronous assertion on the next line can run before the second scrollIntoView call. The component is right; the test asserts too early. Same family as #604 and #1036.

Fix

Wait for the thing being asserted: await waitFor(() => expect(scroll).toHaveBeenCalledTimes(2)). Test only, no behaviour change.

## Seen PR #1038 (no frontend change at all) went red on **CI / Frontend (shard 2/2)**, run https://git.rhoving.com/rbrooks/Quest-Board/actions/runs/1801 (job 63083): ``` FAIL src/pages/table/Preview.test.jsx > Preview > coming into view (#1020) > is brought into view again when a fetched entry arrives and the panel has grown, and then no more AssertionError: expected "vi.fn()" to be called 2 times, but got 1 times ❯ src/pages/table/Preview.test.jsx:197:22 ``` 1 failed, 1572 passed. ## Cause (read from the code; not reproduced locally) `Preview.jsx` brings the panel into view from a passive effect (`useEffect(..., [kind, id, drawn])`). The test does ```js expect(await screen.findByText("Blackfen adder")).toBeInTheDocument(); expect(scroll).toHaveBeenCalledTimes(2); ``` `findByText` resolves as soon as the text is in the DOM, which is at commit. A passive effect runs some time after the commit, so on a busy runner the synchronous assertion on the next line can run before the second `scrollIntoView` call. The component is right; the test asserts too early. Same family as #604 and #1036. ## Fix Wait for the thing being asserted: `await waitFor(() => expect(scroll).toHaveBeenCalledTimes(2))`. Test only, no behaviour change.
Author
Collaborator

Done in PR #1041, merged to main on 2026-10-02 with CI green. The test now waits for the second scrollIntoView call instead of asserting it on the line after the text appears; the component is unchanged.

Before the fix the test failed in three CI runs today (#1038, the re-run of #1034, and #1040), all on a busy runner. Branches opened before this merge need main merged in to pick it up.

Done in PR #1041, merged to main on 2026-10-02 with CI green. The test now waits for the second `scrollIntoView` call instead of asserting it on the line after the text appears; the component is unchanged. Before the fix the test failed in three CI runs today (#1038, the re-run of #1034, and #1040), all on a busy runner. Branches opened before this merge need main merged in to pick it up.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
rbrooks/Quest-Board#1039
No description provided.