diff --git a/src/index.test.ts b/src/index.test.ts index 3fcc2524..da2b39e6 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -155,3 +155,12 @@ test("setScript adds a nonce", () => { const script = document.head.childNodes[0] as HTMLScriptElement; expect(script.nonce).toBe(nonce); }); + +test("loader should resolve immediately when google.maps defined", async () => { + const loader = new Loader({ apiKey: "foo" }); + window.google = { maps: { version: "3.*.*" } as any }; + console.warn = jest.fn(); + await expect(loader.loadPromise()).resolves.toBeUndefined(); + delete window.google; + expect(console.warn).toHaveBeenCalledTimes(1); +}); diff --git a/src/index.ts b/src/index.ts index ef7df056..59f31373 100644 --- a/src/index.ts +++ b/src/index.ts @@ -398,6 +398,14 @@ export class Loader { } private execute(): void { + if (window.google && window.google.maps && window.google.maps.version) { + console.warn( + "Aborted attempt to load Google Maps JS with @googlemaps/js-api-loader." + + "This may result in undesirable behavior as script parameters may not match." + ); + this.callback(); + } + if (this.done) { this.callback(); } else {