I've got the following function in my AngularJS controller:
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 want to test this piece of code, but the then function won't get called. But the geocode function gets called definitely.
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 im getting an async timeout:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
Edit
When I'm returning the resolve
directly, it works as expected:
service.getPlaceByAddress = function(address) {
return $q(function(resolve, reject) {
return resolve();
//geocoder()...
});
};
So I think, the problem is in the callback of the geocoder. This is strange, because the code works perfectly in the browser, but not in the jasmine test...
done
argument, the promise doesn't resolve either... :/ – roNn23