From 44a117390bcede29265ef2d8e08ad8b69f8648a1 Mon Sep 17 00:00:00 2001 From: Maurice Date: Sat, 29 Aug 2026 00:20:45 +0200 Subject: [PATCH] test(maps): stub maplibre-gl-leaflet globally jsdom has no WebGL, so the real vector basemap layer can never work in the client tests. More immediately: several map tests hand react-leaflet a partial useMap() stub with no addLayer on it, which was harmless while the basemap was a stubbed and is not now that it is a real layer - addTo() reaches for map.addLayer and rejects into the void. 79 unhandled rejections, every assertion still green, and vitest fails the run on those. Stubbed in the setup file for the same reason ResizeObserver is: the capability does not exist in this environment. The tests that assert on the layer register their own mock, which takes precedence. --- client/tests/setup.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/client/tests/setup.ts b/client/tests/setup.ts index d0375bea4..4d8c1482e 100644 --- a/client/tests/setup.ts +++ b/client/tests/setup.ts @@ -100,3 +100,25 @@ if (typeof URL.createObjectURL === 'undefined') { // Element.prototype.scrollIntoView — jsdom doesn't implement it Element.prototype.scrollIntoView = vi.fn(); + +// maplibre-gl-leaflet — the vector basemap every Leaflet map draws since the move +// off CARTO. jsdom has no WebGL, so the real layer can never work here; more to +// the point, several map tests hand react-leaflet a partial `useMap()` stub, and +// the real layer's addTo() reaches for map.addLayer and rejects into the void. +// Stubbed globally for the same reason ResizeObserver is: the capability does not +// exist in this environment. Tests that assert on the layer register their own +// mock, which takes precedence over this one. +vi.mock('@maplibre/maplibre-gl-leaflet', () => ({ + maplibreGL: vi.fn(() => { + const gl = { + setStyle: vi.fn(), + on: vi.fn(), + isStyleLoaded: vi.fn(() => false), + getStyle: vi.fn(() => ({ layers: [] })), + setLayoutProperty: vi.fn(), + }; + const layer: Record = { remove: vi.fn(), getMaplibreMap: vi.fn(() => gl) }; + layer.addTo = vi.fn(() => layer); + return layer; + }), +}));