Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save NicholasMurray/baeb1de0d4fcffe2fbe9 to your computer and use it in GitHub Desktop.

Select an option

Save NicholasMurray/baeb1de0d4fcffe2fbe9 to your computer and use it in GitHub Desktop.
AngularJS Geolocation Directive Jasmine Geolocation Available Test
describe('Directive tests: geolocation ', function() {
var $window, navigator;
describe('when called on a browser that has geolocation available ', function() {
beforeEach(module('geolocationApp'));
beforeEach(inject(function($rootScope, $compile, _$window_) {
element = angular.element('<geolocation class="geolocation"><p>This is a geolocation app</p></geolocation>');
scope = $rootScope;
$window = _$window_;
spyOn($window.navigator.geolocation, 'getCurrentPosition').and.callFake(function() {
var position = { coords: { latitude: 12.3, longitude: -32.1 } };
arguments[0](position);
});
$compile(element)(scope);
scope.$digest();
}));
it("should display the current latitude and longitude", function() {
expect(element.find('#latitude').text()).toEqual('12.3');
expect(element.find('#longitude').text()).toEqual('-32.1');
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment