mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-13 15:51:00 +00:00
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:
@@ -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', () => ({
|
||||
|
||||
Reference in New Issue
Block a user