Hello,
I am using the Esri's Javascript API 3.9. I have created functionality that allows a user to add a graphic to the map by clicking on the map. The type of graphic added depends on some previous selection that user has made. For example, selecting one option (say Option A) adds a circle graphic whereas selecting a different option (say Option B) adds a square graphic.
My need for the programmatic map 'click' event is with the automated unit tests I am creating (I am using Jasmine for my unit tests). My hope is to write a unit test which selects programmatically Option A, programmatically triggers a click on the map, and verifies that the correct 'map click' event handler was called (the one that handles the map clicks when Option A is selected).
I have tried using dojo's emit function. The code seems to execute with no errors, i.e. the function call returns an 'event' object, but no map click event handler is ever called. I am pretty sure the event is hooked up correctly because if I follow those same steps manually, the correct event handler is called. As part of my testing, i have tried passing the 'emit' function both the map object and the div which contains the map object. Neither way seems to work, i.e. the click event handler is not called. Its not critical to my testing that a 'correct' argument is passed to the event handler; i just want to know that the correct handler is called.
So, my question is how can i programmatically fire/trigger a map's click event?
Thank you.
//relevant code
this.map = new Map(divId, {
basemap: "streets",
center: [-122, 45.6],
zoom: 5,
smartNavigation: false
});
//passing the div which contains the map
var theMapDiv = dom.byId(divId);
var testEvent = on.emit(theMapDiv, "click", { bubbles: true, cancelable: true });
//passing the map
var testEvent = on.emit(this.map, "click", { bubbles: true, cancelable: true });