Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to override Map methods after initialization #811

Open
GeorgeBatt-SV opened this issue Jan 3, 2025 · 0 comments
Open

Not able to override Map methods after initialization #811

GeorgeBatt-SV opened this issue Jan 3, 2025 · 0 comments
Labels
triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@GeorgeBatt-SV
Copy link

GeorgeBatt-SV commented Jan 3, 2025

I'm following the example 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<InstanceType<typeof google.maps.Map>["getBounds"]>): ReturnType<InstanceType<typeof google.maps.Map>["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.

@GeorgeBatt-SV GeorgeBatt-SV added triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

1 participant