Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

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

Select an option

Save NicholasMurray/78f1c7be22715622f4ff to your computer and use it in GitHub Desktop.
AngularJS Geolocation Directive Jasmine Geolocation Not Available Test
describe('Directive tests: geolocation ', function() {
var $window, navigator;
describe('when called on a browser that does not have 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(error) {
var error = {code: 1};
arguments[1](error);
});
$compile(element)(scope);
scope.$digest();
}));
it("should display a message to inform the user", function() {
expect(element.text()).toEqual('Your geolocation is not available');
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment