dusansen
dusansen

Reputation: 47

Mocking google.maps.LatLng in jest

I am using heatmap layer for google maps, and while mapping data for heatmap, i am using constructor new google.maps.LatLng(lat, lng), and everything works file. In index.html file i have loaded //maps.googleapis.com/maps/api... and i guess that is where i get global google object with which i can call that constructor.

So the real issue is when I try to write unit test for that using Jest. I get the message that google is not defined in global.

I tried to mock global.google in the setup for the tests but couldn't get it done.

Upvotes: 0

Views: 1932

Answers (1)

Justin Poehnelt
Justin Poehnelt

Reputation: 3469

use https://www.npmjs.com/package/@googlemaps/jest-mocks.

import { initialize } from "@googlemaps/jest-mocks";

beforeEach(() => {
  initialize();
});

// Your tests

Upvotes: 1

Related Questions