Skip to content

Not able to override Map methods after initialization #811

@GeorgeBatt-SV

Description

@GeorgeBatt-SV

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    triage meI really want to be triaged.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions