From 322d5d5209775cb3516c5b4d0effe37e82f0a0fc Mon Sep 17 00:00:00 2001 From: Maurice Date: Sun, 8 Nov 2026 00:05:54 +0100 Subject: [PATCH] test(map): the phone hook mock keeps the number of hooks stable The mock called the real useIsPhone only while a test left the answer open, so a map still mounted when the answer was reset rendered with one hook more and React threw. It now calls the real hook every time and overrides only its answer. --- client/src/components/Map/MapView.test.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/client/src/components/Map/MapView.test.tsx b/client/src/components/Map/MapView.test.tsx index b4496cef8..aa4200bb9 100644 --- a/client/src/components/Map/MapView.test.tsx +++ b/client/src/components/Map/MapView.test.tsx @@ -211,7 +211,15 @@ vi.mock('../../services/photoService', () => ({ const shell = vi.hoisted(() => ({ phone: undefined as boolean | undefined })) vi.mock('../../mobile/useIsPhone', async (importOriginal) => { const actual = await importOriginal() - return { ...actual, useIsPhone: () => shell.phone ?? actual.useIsPhone() } + // The real hook runs every time, so a test that changes the answer never changes the + // number of hooks a mounted map has (React throws on that). + return { + ...actual, + useIsPhone: () => { + const real = actual.useIsPhone() + return shell.phone ?? real + }, + } }) vi.mock('./gcj02Crs', () => ({