googlemaps / googlemaps/js-jest-mocks
Not able to override Map methods after initialization
- Dominant language
- TypeScript
- Stars
- 42
- Forks
- 33
- Avg merge
- 1m
- Merged PRs (30d)
- 3
Description
I'm following the [example](https://github.com/googlemaps/js-jest-mocks?tab=readme-ov-file#extending-mocks) to extending mocks in an attempt to change the implementation of `Map.getBounds` to return a new value.
I reassign the `google.maps.Map` global as described using the following:
```
beforeEach(() => {
initialize();
google.maps.Map = class extends google.maps.Map {
getBounds(...args: Parameters["getBounds"]>): ReturnType["getBounds"]> {
// Call a mock, etc..
return new google.maps.LatLngBounds({ lat: 50, lng: 50 });
}
};
});
```
Yet my `getBounds` method is never called. Constructors are called as expected if I override them, but not other methods. Am I doing something wrong?
Additionally, when I override in this fashion, the instance is no longer available when using `mockInstances.get(Map)`. Is that expected?
FWIW, I'm using Vitest, not Jest. But as I understand it the API is synonymous so shouldn't make a difference here.
Contributor guide
Research direction
Start with the README's Extending Mocks example and trace initialize(), the overridden google.maps.Map class, and mockInstances.get(Map). Reproduce the behavior with the provided Vitest-style snippet, then determine whether overridden methods and instance tracking should work; done means the expected behavior is implemented or clearly documented and verified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100