From b2631f61709ae71bb29ec6f1353f2a3c1ad33cd3 Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Tue, 4 Jan 2011 11:53:23 -0800 Subject: rename scope.$inject to scope.$service see changelog diff for more info --- test/servicesSpec.js | 179 +++++++++++++++++++++++++-------------------------- 1 file changed, 87 insertions(+), 92 deletions(-) (limited to 'test/servicesSpec.js') diff --git a/test/servicesSpec.js b/test/servicesSpec.js index e7bf39cb..cff79ae4 100644 --- a/test/servicesSpec.js +++ b/test/servicesSpec.js @@ -1,5 +1,5 @@ describe("service", function(){ - var scope, $xhrError, $log, mockServices, inject, $browser, $browserXhr, $xhrBulk, $xhr, $route; + var scope, $xhrError, $log, mockServices, $browser, $browserXhr, $xhrBulk, $xhr; beforeEach(function(){ $xhrError = jasmine.createSpy('$xhr.error'); @@ -8,13 +8,10 @@ describe("service", function(){ '$xhr.error': $xhrError, '$log': $log }); - inject = scope.$inject; - $browser = inject('$browser'); + $browser = scope.$service('$browser'); $browserXhr = $browser.xhr; - $xhrBulk = scope.$inject('$xhr.bulk'); - $xhr = scope.$inject('$xhr'); - $route = scope.$inject('$route'); - scope.$location = inject('$location'); + $xhrBulk = scope.$service('$xhr.bulk'); + $xhr = scope.$service('$xhr'); }); afterEach(function(){ @@ -24,7 +21,7 @@ describe("service", function(){ it("should inject $window", function(){ - expect(scope.$inject('$window')).toEqual(window); + expect(scope.$service('$window')).toEqual(window); }); xit('should add stylesheets', function(){ @@ -45,7 +42,7 @@ describe("service", function(){ function info(){ logger+= 'info;'; } function error(){ logger+= 'error;'; } var scope = createScope({}, angularService, {$window: {console:{log:log, warn:warn, info:info, error:error}}, $document:[{cookie:''}]}), - $log = scope.$inject('$log'); + $log = scope.$service('$log'); $log.log(); $log.warn(); $log.info(); @@ -57,7 +54,7 @@ describe("service", function(){ var logger = ""; function log(){ logger+= 'log;'; } var scope = createScope({}, angularService, {$window: {console:{log:log}}, $document:[{cookie:''}]}); - var $log = scope.$inject('$log'); + var $log = scope.$service('$log'); $log.log(); $log.warn(); $log.info(); @@ -67,7 +64,7 @@ describe("service", function(){ it('should use noop if no console', function(){ var scope = createScope({}, angularService, {$window: {}, $document:[{cookie:''}]}), - $log = scope.$inject('$log'); + $log = scope.$service('$log'); $log.log(); $log.warn(); $log.info(); @@ -115,98 +112,100 @@ describe("service", function(){ it('should log errors', function(){ var error = ''; $log.error = function(m) { error += m; }; - scope.$inject('$exceptionHandler')('myError'); + scope.$service('$exceptionHandler')('myError'); expect(error).toEqual('myError'); }); }); describe("$location", function(){ - it("should inject $location", function() { - expect(scope.$location).toBeDefined(); + var $location; + + beforeEach(function() { + $location = scope.$service('$location'); }); it("update should update location object immediately", function() { var href = 'http://host:123/p/a/t/h.html?query=value#path?key=value&flag&key2='; - scope.$location.update(href); - expect(scope.$location.href).toEqual(href); - expect(scope.$location.protocol).toEqual("http"); - expect(scope.$location.host).toEqual("host"); - expect(scope.$location.port).toEqual("123"); - expect(scope.$location.path).toEqual("/p/a/t/h.html"); - expect(scope.$location.search).toEqual({query:'value'}); - expect(scope.$location.hash).toEqual('path?key=value&flag&key2='); - expect(scope.$location.hashPath).toEqual('path'); - expect(scope.$location.hashSearch).toEqual({key: 'value', flag: true, key2: ''}); + $location.update(href); + expect($location.href).toEqual(href); + expect($location.protocol).toEqual("http"); + expect($location.host).toEqual("host"); + expect($location.port).toEqual("123"); + expect($location.path).toEqual("/p/a/t/h.html"); + expect($location.search).toEqual({query:'value'}); + expect($location.hash).toEqual('path?key=value&flag&key2='); + expect($location.hashPath).toEqual('path'); + expect($location.hashSearch).toEqual({key: 'value', flag: true, key2: ''}); }); it('toString() should return actual representation', function() { var href = 'http://host:123/p/a/t/h.html?query=value#path?key=value&flag&key2='; - scope.$location.update(href); - expect(scope.$location.toString()).toEqual(href); + $location.update(href); + expect($location.toString()).toEqual(href); scope.$eval(); - scope.$location.host = 'new'; - scope.$location.path = ''; - expect(scope.$location.toString()).toEqual('http://new:123?query=value#path?key=value&flag&key2='); + $location.host = 'new'; + $location.path = ''; + expect($location.toString()).toEqual('http://new:123?query=value#path?key=value&flag&key2='); }); it('toString() should not update browser', function() { var url = $browser.getUrl(); - scope.$location.update('http://www.angularjs.org'); - expect(scope.$location.toString()).toEqual('http://www.angularjs.org'); + $location.update('http://www.angularjs.org'); + expect($location.toString()).toEqual('http://www.angularjs.org'); expect($browser.getUrl()).toEqual(url); }); it('should update browser at the end of $eval', function() { var url = $browser.getUrl(); - scope.$location.update('http://www.angularjs.org/'); - scope.$location.update({path: '/a/b'}); - expect(scope.$location.toString()).toEqual('http://www.angularjs.org/a/b'); + $location.update('http://www.angularjs.org/'); + $location.update({path: '/a/b'}); + expect($location.toString()).toEqual('http://www.angularjs.org/a/b'); expect($browser.getUrl()).toEqual(url); scope.$eval(); expect($browser.getUrl()).toEqual('http://www.angularjs.org/a/b'); }); it('should update hashPath and hashSearch on hash update', function(){ - scope.$location.update('http://server/#path?a=b'); + $location.update('http://server/#path?a=b'); scope.$eval(); - scope.$location.update({hash: ''}); + $location.update({hash: ''}); - expect(scope.$location.hashPath).toEqual(''); - expect(scope.$location.hashSearch).toEqual({}); + expect($location.hashPath).toEqual(''); + expect($location.hashSearch).toEqual({}); }); it('should update hash on hashPath or hashSearch update', function() { - scope.$location.update('http://server/#path?a=b'); + $location.update('http://server/#path?a=b'); scope.$eval(); - scope.$location.update({hashPath: '', hashSearch: {}}); + $location.update({hashPath: '', hashSearch: {}}); - expect(scope.$location.hash).toEqual(''); + expect($location.hash).toEqual(''); }); it('should update hashPath and hashSearch on hash property change', function(){ - scope.$location.update('http://server/#path?a=b'); + $location.update('http://server/#path?a=b'); scope.$eval(); - scope.$location.hash = ''; + $location.hash = ''; - expect(scope.$location.toString()).toEqual('http://server/'); - expect(scope.$location.hashPath).toEqual(''); - expect(scope.$location.hashSearch).toEqual({}); + expect($location.toString()).toEqual('http://server/'); + expect($location.hashPath).toEqual(''); + expect($location.hashSearch).toEqual({}); }); it('should update hash on hashPath or hashSearch property change', function() { - scope.$location.update('http://server/#path?a=b'); + $location.update('http://server/#path?a=b'); scope.$eval(); - scope.$location.hashPath = ''; - scope.$location.hashSearch = {}; + $location.hashPath = ''; + $location.hashSearch = {}; - expect(scope.$location.toString()).toEqual('http://server/'); - expect(scope.$location.hash).toEqual(''); + expect($location.toString()).toEqual('http://server/'); + expect($location.hash).toEqual(''); }); it('should update hash before any processing', function(){ scope = compile('