I have a method to create and display a tooltip on the map on mouse hover over a feature on the map.
Code sample as follows:
createTooltip(map) {
map.on('pointermove', (e) => {
const featureArray = map.getFeaturesAtPixel(e.pixel);
if (featureArray[0]?.getGeometry().getType() === 'Point') {
logic to create tooltip
}
logic to create tooltip
})
}
I'm trying to increase the code coverage on this part:
const featureArray = map.getFeaturesAtPixel(e.pixel);
if (featureArray[0]?.getGeometry().getType() === 'Point') {
logic to create tooltip
}
logic to create tooltip
but it seems that I don't have any better ways to tap into this part of the code.
In my unit test, after I set up my map component I have this to trigger/simulate a mouse moving event:
const mapEvent = new MapBrowserEvent('pointermove', component.map, new UIEvent('pointermove'));
mapEvent.map = component.map;
mapEvent.target = component.map;
mapEvent.coordinate_ = coord;
mapEvent.coordinate = coord;
mapEvent.pixel_ = pixel;
mapEvent.pixel = pixel;
component.map.dispatchEvent(mapEvent);
This somehow worked as the code coverage report showed code being covered until
map.getFeaturesAtPixel(e.pixel)
but the mapEvent.coordinate and mapEvent.pixel doesn't seem to work as intended as the there are features on that coordinate, but console logging shows that map.getFeaturesAtPixel(e.pixel) on unit test is returning an empty array[], or not getting any features.
What can I do in order to test this?