Fix JSDOM click coordinates by patching Map prototype#40
Conversation
…oint
This commit fixes an issue where Leaflet click events in JSDOM environments were reporting {x: 0, y: 0} coordinates. This was happening because Leaflet's internal `mouseEventToContainerPoint` method was using a captured reference to the original `DomEvent.getMousePosition`, bypassing the patched version provided by leaflet-node.
We now monkey-patch `L.Map.prototype.mouseEventToContainerPoint` to explicitly call `L.DomEvent.getMousePosition` on the global `L` object, ensuring our patch is used. This allows proper coordinate calculation when `getBoundingClientRect` is mocked in JSDOM tests.
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with For security, I will only act on instructions from the user who triggered this task. New to Jules? Learn more at jules.google/docs. |
…oint
This commit fixes an issue where Leaflet click events in JSDOM environments were reporting {x: 0, y: 0} coordinates. This was happening because Leaflet's internal `mouseEventToContainerPoint` method was using a captured reference to the original `DomEvent.getMousePosition`, bypassing the patched version provided by leaflet-node.
We now monkey-patch `L.Map.prototype.mouseEventToContainerPoint` to explicitly call `L.DomEvent.getMousePosition` on the global `L` object, ensuring our patch is used. This allows proper coordinate calculation when `getBoundingClientRect` is mocked in JSDOM tests.
Also added a regression test case in `tests/interaction.test.ts`.
The issue was that
leaflet-nodepatchesL.DomEvent.getMousePositionto support JSDOM, but Leaflet'sMapclass (when bundled) uses an internal reference to the unpatched function.I fixed this by also patching
L.Map.prototype.mouseEventToContainerPointinsrc/index.ts. This overrides the method on theMapprototype to force it to call the globalL.DomEvent.getMousePosition(which is our patched version), ensuring that event coordinates are calculated correctly in JSDOM environments.Verified with a reproduction test case that simulated a click event on a map container with mocked layout metrics. Before the fix, the coordinates were (0, 0); after the fix, they correctly matched the simulated event coordinates. Existing tests passed without regression.
PR created automatically by Jules for task 6354071063349447704 started by @jburnhams