Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import { Loader, LoaderOptions } from ".";

test.each([
[{}, "https://maps.googleapis.com/maps/api/js?callback=__googleMapsCallback"],
[
{ apiKey: "foo" },
"https://maps.googleapis.com/maps/api/js?callback=__googleMapsCallback&key=foo",
Expand Down Expand Up @@ -114,9 +115,3 @@ test("loader should wait if already loading", () => {

loader.load();
});

test("loader should throw exception if invalid key format", () => {
expect(() => new Loader({ apiKey: "" })).toThrow();
expect(() => new Loader({ apiKey: {} as string })).toThrow();
expect(() => new Loader({ apiKey: (1 as unknown) as string })).toThrow();
});
9 changes: 4 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,6 @@ export class Loader {
region,
version,
}: LoaderOptions) {
if (typeof apiKey !== "string" || !apiKey) {
throw "Invalid apiKey " + apiKey;
}

this.version = version;
this.apiKey = apiKey;
this.libraries = libraries;
Expand All @@ -211,7 +207,10 @@ export class Loader {
let url = this.URL;

url += `?callback=${this.CALLBACK}`;
url += `&key=${this.apiKey}`;

if (this.apiKey) {
url += `&key=${this.apiKey}`;
}

if (this.libraries.length > 0) {
url += `&libraries=${this.libraries.join(",")}`;
Expand Down