Reputation: 47
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
Reputation: 3469
use https://www.npmjs.com/package/@googlemaps/jest-mocks.
import { initialize } from "@googlemaps/jest-mocks";
beforeEach(() => {
initialize();
});
// Your tests
Upvotes: 1