Problem
client/src/components/wiki/tabs/BrowseTab.test.jsx fails intermittently in a full cd client && npm test run and passes every time in isolation. Observed once in a run of 832 files (1 failed | 830 passed), then green on an immediate re-run of the identical tree.
The failure is a Testing Library "unable to find an element" throw out of the suite's own helper, which queries the Save control the moment the tab mounts:
const clickSave = async () => {
const before = api.updateNote.mock.calls.length;
fireEvent.click(screen.getByRole('button', { name: /Save/ })); // <- throws here
await waitFor(() => expect(api.updateNote.mock.calls.length).toBe(before + 1));
};
getByRole is synchronous, so under contention (the client suite runs two jsdom workers) the click happens before the editor has finished mounting and the button exists. The dumped DOM in the failure shows the surrounding icon markup rendered but not the control the query wants.
This is the same class as #5857 (ChiefOfStaff page tests flake under full-suite load by querying an unsettled page mount), but a different file — that issue names only the ChiefOfStaff suite, so this one is not covered by it.
Work
Make the helper wait for the control instead of assuming it is present: await screen.findByRole('button', { name: /Save/ }) before the fireEvent.click, and give any other synchronous first-query in the file the same treatment. Do not paper over it with a bare timeout.
While in the file, check whether the mount that precedes clickSave is itself awaited — an unawaited render is the usual upstream cause, and fixing it there is better than making each query async.
Acceptance criteria
- No synchronous
getBy* query in BrowseTab.test.jsx runs against a mount that has not settled.
- The suite still passes in isolation and in a full
cd client && npm test.
- Assertions are otherwise unchanged — this is a flake fix, not a rewrite.
Files
client/src/components/wiki/tabs/BrowseTab.test.jsx
Problem
client/src/components/wiki/tabs/BrowseTab.test.jsxfails intermittently in a fullcd client && npm testrun and passes every time in isolation. Observed once in a run of 832 files (1 failed | 830 passed), then green on an immediate re-run of the identical tree.The failure is a Testing Library "unable to find an element" throw out of the suite's own helper, which queries the Save control the moment the tab mounts:
getByRoleis synchronous, so under contention (the client suite runs two jsdom workers) the click happens before the editor has finished mounting and the button exists. The dumped DOM in the failure shows the surrounding icon markup rendered but not the control the query wants.This is the same class as #5857 (ChiefOfStaff page tests flake under full-suite load by querying an unsettled page mount), but a different file — that issue names only the ChiefOfStaff suite, so this one is not covered by it.
Work
Make the helper wait for the control instead of assuming it is present:
await screen.findByRole('button', { name: /Save/ })before thefireEvent.click, and give any other synchronous first-query in the file the same treatment. Do not paper over it with a bare timeout.While in the file, check whether the mount that precedes
clickSaveis itself awaited — an unawaited render is the usual upstream cause, and fixing it there is better than making each query async.Acceptance criteria
getBy*query inBrowseTab.test.jsxruns against a mount that has not settled.cd client && npm test.Files
client/src/components/wiki/tabs/BrowseTab.test.jsx