From 530c429e5a49b7d13f7f015c8246de8558cca1de Mon Sep 17 00:00:00 2001 From: Florian Date: Sat, 31 Oct 2026 19:33:36 +0100 Subject: [PATCH] test(web): give the retried map's container a size in the pin test The test that replaces the map gave the replacement a fake container without getBoundingClientRect. The visible label is fitted against the container on the next animation frame. The test usually unmounted first, which cancels that frame, but on a slow runner the frame ran and threw outside the test, and Vitest failed the web run with an unhandled error. The replacement container now has the same size as the first map's, and the test waits for that frame before it unmounts, so it always runs the fit on the replacement map. --- apps/web/src/hooks/usePinMarker.test.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/apps/web/src/hooks/usePinMarker.test.tsx b/apps/web/src/hooks/usePinMarker.test.tsx index bbe47a55d..ffe93cb01 100644 --- a/apps/web/src/hooks/usePinMarker.test.tsx +++ b/apps/web/src/hooks/usePinMarker.test.tsx @@ -162,6 +162,10 @@ it("reattaches the pin after the map is replaced by a retry", async () => { expect(fake.map.getCanvasContainer().querySelector("span")?.textContent).toBe("Station"); const replacement = createFakeMap({ styleLoaded: true }); + // The visible label is fitted against the new map's container on the next frame. + Object.assign(replacement.map.getContainer(), { + getBoundingClientRect: () => new DOMRect(0, 0, 1200, 800), + }); mapRef.current = replacement.map; styleVersion++; view.rerender(); @@ -169,6 +173,7 @@ it("reattaches the pin after the map is replaced by a retry", async () => { expect(fake.map.getCanvasContainer().querySelector("span")).toBeNull(); expect(replacement.map.getCanvasContainer().querySelector("span")?.textContent).toBe("Station"); + await act(async () => new Promise((resolve) => requestAnimationFrame(() => resolve()))); view.unmount(); mapRef.current = fake.map; styleVersion = 0;