diff --git a/package.json b/package.json index a0f112fe4..9c512c024 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,8 @@ "format": "eslint . --fix", "lint": "eslint .", "prepare": "rm -rf dist && rollup -c", - "test": "jest src/*" + "test": "jest src/*", + "test:watch": "jest --watch src/*" }, "devDependencies": { "@rollup/plugin-typescript": "^8.3.0", diff --git a/src/data.feature.test.ts b/src/data.feature.test.ts new file mode 100644 index 000000000..917e2e794 --- /dev/null +++ b/src/data.feature.test.ts @@ -0,0 +1,22 @@ +/** + * Copyright 2019 Google LLC. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { initialize } from "./index"; + +test("feature object is mocked", () => { + initialize(); + expect(new google.maps.Data.Feature(null)).toBeTruthy(); +}); diff --git a/src/data.feature.ts b/src/data.feature.ts new file mode 100644 index 000000000..490d4f265 --- /dev/null +++ b/src/data.feature.ts @@ -0,0 +1,59 @@ +/** + * Copyright 2019 Google LLC. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export class Feature implements google.maps.Data.Feature { + constructor(options?: google.maps.Data.FeatureOptions | null) {} + public forEachProperty = jest + .fn() + .mockImplementation((callback: (a: any, b: string) => void) => { + return null; + }); + public getGeometry = jest.fn().mockImplementation(() => { + return null; + }); + public getId = jest.fn().mockImplementation(() => { + return "1"; + }); + public getProperty = jest.fn().mockImplementation((name: string) => { + return undefined; + }); + public removeProperty = jest.fn().mockImplementation((name: string) => { + return null; + }); + public setGeometry = jest + .fn() + .mockImplementation( + ( + newGeometry: + | google.maps.Data.Geometry + | null + | google.maps.LatLng + | google.maps.LatLngLiteral + ) => { + return null; + } + ); + public setProperty = jest + .fn() + .mockImplementation((name: string, newValue: any) => { + return null; + }); + public toGeoJson = jest + .fn() + .mockImplementation((callback: (a: object) => void) => { + return null; + }); +} diff --git a/src/data.ts b/src/data.ts index 9518ec392..7b132a2ba 100644 --- a/src/data.ts +++ b/src/data.ts @@ -14,12 +14,18 @@ * limitations under the License. */ +import { Feature } from "./data.feature"; import { MVCObject } from "./mvcobject"; export class Data extends MVCObject implements google.maps.Data { constructor(opt?: google.maps.Data.DataOptions | null) { super(); } + public static Feature = jest + .fn() + .mockImplementation( + (options?: google.maps.Data.FeatureOptions | null) => new Feature(options) + ); public add = jest .fn() .mockImplementation( diff --git a/src/index.ts b/src/index.ts index 71e0bf4d3..6982ca65d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -21,6 +21,7 @@ import { LatLng, LatLngBounds } from "./latlng"; import { Autocomplete } from "./places/autocomplete"; import { Circle } from "./circle"; import { Data } from "./data"; +import { Feature } from "./data.feature"; import { MVCArray } from "./mvcarray"; import { MVCObject } from "./mvcobject"; import { MapCanvasProjection } from "./mapcanvasprojection"; @@ -83,6 +84,7 @@ export { Marker, Map_ as Map, Data, + Feature, Size, MapCanvasProjection, MapPanes,