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.
This commit is contained in:
Maurice
2026-11-08 00:05:54 +01:00
parent 0346f9c13d
commit 322d5d5209
+9 -1
View File
@@ -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<typeof import('../../mobile/useIsPhone')>()
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', () => ({