diff --git a/src/components/__tests__/api-provider.test.tsx b/src/components/__tests__/api-provider.test.tsx index 010f391b..da8f5354 100644 --- a/src/components/__tests__/api-provider.test.tsx +++ b/src/components/__tests__/api-provider.test.tsx @@ -80,6 +80,13 @@ test('passes parameters to GoogleMapsAPILoader', () => { }); }); +test('passes parameters to GoogleMapsAPILoader', () => { + render(); + + const actual = apiLoadSpy.mock.lastCall[0]; + expect(Object.keys(actual)).toMatchObject(['key']); +}); + test('renders inner components', async () => { const LoadingStatus = () => { const mapsLoaded = useApiIsLoaded(); diff --git a/src/components/api-provider.tsx b/src/components/api-provider.tsx index c9f4b0aa..869f8da6 100644 --- a/src/components/api-provider.tsx +++ b/src/components/api-provider.tsx @@ -8,7 +8,10 @@ import React, { useState } from 'react'; -import {GoogleMapsApiLoader} from '../libraries/google-maps-api-loader'; +import { + ApiParams, + GoogleMapsApiLoader +} from '../libraries/google-maps-api-loader'; import {APILoadingStatus} from '../libraries/api-loading-status'; type ImportLibraryFunction = typeof google.maps.importLibrary; @@ -143,15 +146,11 @@ function useGoogleMapsApiLoader(props: APIProviderProps) { () => { (async () => { try { - await GoogleMapsApiLoader.load( - { - key: apiKey, - v: version, - libraries: librariesString, - ...otherApiParams - }, - status => setStatus(status) - ); + const params: ApiParams = {key: apiKey, ...otherApiParams}; + if (version) params.v = version; + if (librariesString?.length > 0) params.libraries = librariesString; + + await GoogleMapsApiLoader.load(params, status => setStatus(status)); for (const name of ['core', 'maps', ...libraries]) { await importLibrary(name);