js-api-loader icon indicating copy to clipboard operation
js-api-loader copied to clipboard

Problem with mocking the Loader in Jest

Open Hajzenberg opened this issue 2 years ago • 0 comments

I'm trying to mock the Loader in Jest so I can test if loader.load() method is being invoked in my code.

I've tried with:

jest.mock('@googlemaps/js-api-loader', () => {
const actual = jest.requireActual('@googlemaps/js-api-loader');
return {
  ...actual,
  Loader: jest.fn().mockImplementation(() => {
    return {
      load: jest.fn(),
    };
  }),
};
});

But during the test invocation is fails with loader.load is not a function. Any idea how to mock it successfully?

Hajzenberg avatar Jun 12 '22 20:06 Hajzenberg