In my AngularJS controller, I have the following function:
service.getPlaceByAddress = function(address) {
return $q(function(resolve, reject) {
geocoder().geocode({'address': address}, function(result, status) {
// gets called
if (status === google.maps.GeocoderStatus.OK) {
return resolve(result);
}
return reject();
});
});
};
I'm having trouble testing this code snippet as the then function isn't being called, even though the geocode function is definitely executed.
it('returns an error if the data service returns no results', function(done) {
GoogleMaps.getPlaceByAddress('Testlocation').then(function() {
done();
// gets never called
});
$scope.$digest();
});
Instead of getting the expected result, I'm encountering an async timeout:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
Update
Upon further investigation, when I directly return resolve
, the function works as intended:
service.getPlaceByAddress = function(address) {
return $q(function(resolve, reject) {
return resolve();
//geocoder()...
});
};
It seems like the issue lies within the geocoder's callback. Oddly enough, the code functions properly in the browser but fails in the jasmine test...