Looking to validate the functionality of my custom Google Maps geocoder directive. In my code, I've set up a geocode constructor that I have already partially implemented:
...
link: function(scope) {
var map,
geocoder,
myLatLng,
mapOptions = {
zoom: 1,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
geocoder = new google.maps.Geocoder();
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
geocoder.geocode({'address': 'New York'}, function(results, status) {
myLatLng = new google.maps.LatLng(results[0].geometry.location.lat(),
results[0].geometry.location.lng());
}});
}
This is followed by my stubbing code:
MapsGeocoderStub = sinon.stub();
$window.google = {
maps: {
Geocoder: MapsGeocoderStub
}
};
I am interested in testing the geocode.geocoder()
function to see if it's being called correctly. To achieve this, I believe I may need to modify the stub to mimic the behavior of the constructor google.maps.Geocoder()
.
Is utilizing a stub the most appropriate approach for achieving this task?