Skip to content

Instantly share code, notes, and snippets.

@ischenkodv
Created February 28, 2015 20:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ischenkodv/8f663a4194a12c7474c7 to your computer and use it in GitHub Desktop.
Save ischenkodv/8f663a4194a12c7474c7 to your computer and use it in GitHub Desktop.
describe('findByNavigator()', function() {
var geolocator, fnDone, fnFail;
beforeEach(function() {
geolocator = new Geolocator({language: 'fi'});
});
it('can find user location', function() {
var location, address, components;
fnDone = jasmine.createSpy('done').and.callFake(function(l, a, c) {
location = l;
address = a;
components = c;
});
fnFail = jasmine.createSpy('fail');
spyOn(geolocator, 'getGeocoder').and.callFake(function(){
var fakeGeolocator = {
geocode: function(params, callback) {
var result = fakeGeocoderResult;
callback(result, google.maps.GeocoderStatus.OK);
}
};
return fakeGeolocator;
});
spyOn(navigator.geolocation, 'getCurrentPosition').and.callFake(function(callback){
var position = {
coords: {
latitude: 60,
longitude: 24
}
};
callback(position);
});
var request = geolocator.findByNavigator();
request.done(fnDone);
request.fail(fnFail);
expect(fnDone).toHaveBeenCalled();
expect(fnFail).not.toHaveBeenCalled();
expect(location instanceof google.maps.LatLng).toEqual(true);
expect(location.toString()).toEqual('(60, 24)');
expect(address).toEqual('Helsinki, Suomi');
expect(components.location).toEqual(location);
expect(components.address).toEqual('Helsinki, Suomi');
expect(components.postcode).toEqual('00100');
expect(components.city).toEqual('Helsinki');
expect(components.country).toEqual('Suomi');
expect(components.region).toEqual('Helsinki');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment