From 42ac5693c5fa40502983fe34b68bcc4c3c70d07f Mon Sep 17 00:00:00 2001 From: Konstantin Alekseev Date: Mon, 18 May 2015 10:33:46 +0300 Subject: [PATCH] Remove unnecessary $apply & fix test for it --- src/geolocation.js | 2 +- test/geolocation.js | 39 +++++++++++++++++++++++++-------------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/geolocation.js b/src/geolocation.js index e39baf5..634aa85 100644 --- a/src/geolocation.js +++ b/src/geolocation.js @@ -41,7 +41,7 @@ angular.module('geolocation') else { $rootScope.$broadcast('error',geolocation_msgs['errors.location.unsupportedBrowser']); - $rootScope.$apply(function(){deferred.reject(geolocation_msgs['errors.location.unsupportedBrowser']);}); + deferred.reject(geolocation_msgs['errors.location.unsupportedBrowser']); } return deferred.promise; } diff --git a/test/geolocation.js b/test/geolocation.js index 8de0b50..93cfc41 100644 --- a/test/geolocation.js +++ b/test/geolocation.js @@ -27,20 +27,6 @@ describe('Service: geolocation', function () { expect(results).toEqual({ coords : { latitude : 32, longitude : -96 } }); }); - it('should not obtain user location due to missing geolocation', function () { - var results,old_navigator; - spyOn($rootScope, '$broadcast'); - old_navigator = $window.navigator; - $window.navigator = {geolocation:false}; - geolocation.getLocation().then(function(){},function(error) { - results = error; - }); - $rootScope.$digest(); - expect($rootScope.$broadcast).toHaveBeenCalledWith('error',geolocation_msgs['errors.location.unsupportedBrowser']); - expect(results).toEqual(geolocation_msgs['errors.location.unsupportedBrowser']); - $window.navigator = old_navigator; - }); - it('should not obtain user location due to rejected permission', function () { var results; spyOn($rootScope, '$broadcast'); @@ -87,3 +73,28 @@ describe('Service: geolocation', function () { }); }); + +describe('Geolocation unsupported', function () { + + // load the service's module + beforeEach(module('geolocation')); + + beforeEach(function() { + module(function ($provide) { + $provide.value('$window', { + navigator: false + }); + }); + }); + + it('should not obtain user location due to missing geolocation', inject(function ($rootScope, geolocation, geolocation_msgs) { + var results; + spyOn($rootScope, '$broadcast'); + geolocation.getLocation().then(function(){},function(error) { + results = error; + }); + $rootScope.$digest(); + expect($rootScope.$broadcast).toHaveBeenCalledWith('error',geolocation_msgs['errors.location.unsupportedBrowser']); + expect(results).toEqual(geolocation_msgs['errors.location.unsupportedBrowser']); + })); +});