From f7f467bce1dece041c6ff3ba79eea74373df5fb9 Mon Sep 17 00:00:00 2001 From: Martin Schuhfuss Date: Fri, 6 Sep 2024 15:44:36 +0200 Subject: [PATCH] fix(map): undefined rendering-type and color-scheme when color-scheme and/or rendering-type aren't specified, they were still passed as properties with undefined value to the google.maps.Map-constructor. This is fixed here, along with the test that failed to detect that problem. --- src/components/__tests__/map.test.tsx | 2 +- src/components/map/use-map-instance.ts | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/components/__tests__/map.test.tsx b/src/components/__tests__/map.test.tsx index 6fc45ac..7a043e1 100644 --- a/src/components/__tests__/map.test.tsx +++ b/src/components/__tests__/map.test.tsx @@ -110,7 +110,7 @@ describe('creating and updating map instance', () => { const [actualEl, actualOptions] = createMapSpy.mock.lastCall!; expect(screen.getByTestId('map')).toContainElement(actualEl); - expect(actualOptions).toMatchObject({ + expect(actualOptions).toStrictEqual({ center: {lat: 53.55, lng: 10.05}, zoom: 12, mapId: 'mymapid' diff --git a/src/components/map/use-map-instance.ts b/src/components/map/use-map-instance.ts index 06cee52..4b332b2 100644 --- a/src/components/map/use-map-instance.ts +++ b/src/components/map/use-map-instance.ts @@ -137,10 +137,15 @@ export function useMapInstance( mapDiv = document.createElement('div'); mapDiv.style.height = '100%'; container.appendChild(mapDiv); + map = new google.maps.Map(mapDiv, { ...mapOptions, - renderingType: renderingType as google.maps.RenderingType, - colorScheme: colorScheme as google.maps.ColorScheme + ...(renderingType + ? {renderingType: renderingType as google.maps.RenderingType} + : {}), + ...(colorScheme + ? {colorScheme: colorScheme as google.maps.ColorScheme} + : {}) }); }