From 4f7802ba287b808d4f658aa231588061c18ef5bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Tue, 3 Nov 2026 20:58:38 +0100 Subject: [PATCH] test(browser): leave no state behind for the next case Await the form's explicit unmount: an unmount left running overlaps the next render's act, and React then commits nothing for the rest of the file. Return to the newest history entry after stepping back, so the next case's push adds an entry instead of replacing the forward one. --- .../measurements/__tests__/measurement-form.browser.test.tsx | 5 ++++- src/hooks/__tests__/use-url-filter-sync.browser.test.tsx | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/components/measurements/__tests__/measurement-form.browser.test.tsx b/src/components/measurements/__tests__/measurement-form.browser.test.tsx index 10a5b9007..cd837a113 100644 --- a/src/components/measurements/__tests__/measurement-form.browser.test.tsx +++ b/src/components/measurements/__tests__/measurement-form.browser.test.tsx @@ -289,7 +289,10 @@ describe(" type", () => { await first.screen.getByLabelText("Value (kg)").fill("80"); await first.save.click(); await expect.poll(() => first.onSuccess.mock.calls.length).toBe(1); - first.screen.unmount(); + // Awaited: the unmount runs inside `act`, and one left running overlaps + // the next render's `act`, after which React commits nothing for the + // rest of the file (every later case finds an empty container). + await first.screen.unmount(); const { screen } = await mount(); await expect diff --git a/src/hooks/__tests__/use-url-filter-sync.browser.test.tsx b/src/hooks/__tests__/use-url-filter-sync.browser.test.tsx index 6897b0b2e..deadc0e47 100644 --- a/src/hooks/__tests__/use-url-filter-sync.browser.test.tsx +++ b/src/hooks/__tests__/use-url-filter-sync.browser.test.tsx @@ -242,6 +242,11 @@ describe("useUrlFilterSync with FilterBar", () => { window.history.back(); await expectSearch("?type=WEIGHT"); await expect.element(pill("Type: Weight")).toBeInTheDocument(); + // Back to the newest entry. Left one step behind, the page keeps a + // forward entry, and the next case's push replaces it instead of adding + // one: `history.length` stays put and its count of entries is off by one. + window.history.forward(); + await expectSearch("?type=PULSE"); }); it("keeps the state in memory and the address untouched with syncToUrl off", async () => {