diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/AngularSpec.js | 2 | ||||
| -rw-r--r-- | test/BinderTest.js | 16 | ||||
| -rw-r--r-- | test/ResourceSpec.js | 8 | ||||
| -rw-r--r-- | test/ScenarioSpec.js | 6 | ||||
| -rw-r--r-- | test/ValidatorsTest.js | 2 | ||||
| -rw-r--r-- | test/servicesSpec.js | 179 | ||||
| -rw-r--r-- | test/widgetsSpec.js | 16 |
7 files changed, 112 insertions, 117 deletions
diff --git a/test/AngularSpec.js b/test/AngularSpec.js index f5a202fe..6f943af8 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -322,7 +322,7 @@ describe('angular service', function() { angular.service('fake', function() { return 'old'; }); angular.service('fake', function() { return 'new'; }); - expect(scope.$inject('fake')).toEqual('new'); + expect(scope.$service('fake')).toEqual('new'); }); it('should preserve $ properties on override', function() { diff --git a/test/BinderTest.js b/test/BinderTest.js index c5c81ee9..53a61eb0 100644 --- a/test/BinderTest.js +++ b/test/BinderTest.js @@ -515,38 +515,38 @@ BinderTest.prototype.testValidateForm = function() { var items = [{}, {}]; c.scope.$set("items", items); c.scope.$eval(); - assertEquals(3, c.scope.$inject('$invalidWidgets').length); + assertEquals(3, c.scope.$service('$invalidWidgets').length); c.scope.$set('name', ''); c.scope.$eval(); - assertEquals(3, c.scope.$inject('$invalidWidgets').length); + assertEquals(3, c.scope.$service('$invalidWidgets').length); c.scope.$set('name', ' '); c.scope.$eval(); - assertEquals(3, c.scope.$inject('$invalidWidgets').length); + assertEquals(3, c.scope.$service('$invalidWidgets').length); c.scope.$set('name', 'abc'); c.scope.$eval(); - assertEquals(2, c.scope.$inject('$invalidWidgets').length); + assertEquals(2, c.scope.$service('$invalidWidgets').length); items[0].name = 'abc'; c.scope.$eval(); - assertEquals(1, c.scope.$inject('$invalidWidgets').length); + assertEquals(1, c.scope.$service('$invalidWidgets').length); items[1].name = 'abc'; c.scope.$eval(); - assertEquals(0, c.scope.$inject('$invalidWidgets').length); + assertEquals(0, c.scope.$service('$invalidWidgets').length); }; BinderTest.prototype.testValidateOnlyVisibleItems = function(){ var c = this.compile('<div><input name="name" ng:required><input ng:show="show" name="name" ng:required></div>', undefined, jqLite(document.body)); c.scope.$set("show", true); c.scope.$eval(); - assertEquals(2, c.scope.$inject('$invalidWidgets').length); + assertEquals(2, c.scope.$service('$invalidWidgets').length); c.scope.$set("show", false); c.scope.$eval(); - assertEquals(1, c.scope.$inject('$invalidWidgets').visible()); + assertEquals(1, c.scope.$service('$invalidWidgets').visible()); }; BinderTest.prototype.testDeleteAttributeIfEvaluatesFalse = function() { diff --git a/test/ResourceSpec.js b/test/ResourceSpec.js index cedd87ce..8b78df12 100644 --- a/test/ResourceSpec.js +++ b/test/ResourceSpec.js @@ -162,8 +162,8 @@ describe("resource", function() { it('should excersize full stack', function(){ var scope = angular.compile('<div></div>'); - var $browser = scope.$inject('$browser'); - var $resource = scope.$inject('$resource'); + var $browser = scope.$service('$browser'); + var $resource = scope.$service('$resource'); var Person = $resource('/Person/:id'); $browser.xhr.expectGET('/Person/123').respond('\n{\n"name":\n"misko"\n}\n'); var person = Person.get({id:123}); @@ -174,8 +174,8 @@ describe("resource", function() { it('should return the same object when verifying the cache', function(){ var scope = angular.compile('<div></div>'); - var $browser = scope.$inject('$browser'); - var $resource = scope.$inject('$resource'); + var $browser = scope.$service('$browser'); + var $resource = scope.$service('$resource'); var Person = $resource('/Person/:id', null, {query: {method:'GET', isArray: true, verifyCache: true}}); $browser.xhr.expectGET('/Person/123').respond('[\n{\n"name":\n"misko"\n}\n]'); var person = Person.query({id:123}); diff --git a/test/ScenarioSpec.js b/test/ScenarioSpec.js index ec016635..30a3d72a 100644 --- a/test/ScenarioSpec.js +++ b/test/ScenarioSpec.js @@ -42,7 +42,7 @@ describe("ScenarioSpec: Compilation", function(){ it("should have $ objects", function(){ scope = compile('<div></div>', {$config: {a:"b"}}); - expect(scope.$inject('$location')).toBeDefined(); + expect(scope.$service('$location')).toBeDefined(); expect(scope.$get('$eval')).toBeDefined(); expect(scope.$get('$config')).toBeDefined(); expect(scope.$get('$config.a')).toEqual("b"); @@ -53,8 +53,8 @@ describe("ScenarioSpec: Compilation", function(){ it("should take location object", function(){ var url = "http://server/#?book=moby"; scope = compile("<div>{{$location}}</div>"); - var $location = scope.$inject('$location'); - var $browser = scope.$inject('$browser'); + var $location = scope.$service('$location'); + var $browser = scope.$service('$browser'); expect($location.hashSearch.book).toBeUndefined(); $browser.setUrl(url); $browser.poll(); diff --git a/test/ValidatorsTest.js b/test/ValidatorsTest.js index d6df7184..c59aaf77 100644 --- a/test/ValidatorsTest.js +++ b/test/ValidatorsTest.js @@ -128,7 +128,7 @@ describe('Validator:asynchronous', function(){ it("should not make second request to same value", function(){ asynchronous.call(self, "kai", function(v,f){value=v; fn=f;}); expect(value).toEqual('kai'); - expect(self.$inject('$invalidWidgets')[0]).toEqual(self.$element); + expect(self.$service('$invalidWidgets')[0]).toEqual(self.$element); var spy = jasmine.createSpy(); asynchronous.call(self, "kai", spy); 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('<div>'); - scope.$location = scope.$inject('$location'); + scope.$location = scope.$service('$location'); var log = ''; scope.$watch('$location.hash', function(){ log += this.$location.hashPath + ';'; @@ -220,37 +219,37 @@ describe("service", function(){ }); it('udpate() should accept hash object and update only given properties', function() { - scope.$location.update("http://host:123/p/a/t/h.html?query=value#path?key=value&flag&key2="); - scope.$location.update({host: 'new', port: 24}); + $location.update("http://host:123/p/a/t/h.html?query=value#path?key=value&flag&key2="); + $location.update({host: 'new', port: 24}); - expect(scope.$location.host).toEqual('new'); - expect(scope.$location.port).toEqual(24); - expect(scope.$location.protocol).toEqual('http'); - expect(scope.$location.href).toEqual("http://new:24/p/a/t/h.html?query=value#path?key=value&flag&key2="); + expect($location.host).toEqual('new'); + expect($location.port).toEqual(24); + expect($location.protocol).toEqual('http'); + expect($location.href).toEqual("http://new:24/p/a/t/h.html?query=value#path?key=value&flag&key2="); }); it('updateHash() should accept one string argument to update path', function() { - scope.$location.updateHash('path'); - expect(scope.$location.hash).toEqual('path'); - expect(scope.$location.hashPath).toEqual('path'); + $location.updateHash('path'); + expect($location.hash).toEqual('path'); + expect($location.hashPath).toEqual('path'); }); it('updateHash() should accept one hash argument to update search', function() { - scope.$location.updateHash({a: 'b'}); - expect(scope.$location.hash).toEqual('?a=b'); - expect(scope.$location.hashSearch).toEqual({a: 'b'}); + $location.updateHash({a: 'b'}); + expect($location.hash).toEqual('?a=b'); + expect($location.hashSearch).toEqual({a: 'b'}); }); it('updateHash() should accept path and search both', function() { - scope.$location.updateHash('path', {a: 'b'}); - expect(scope.$location.hash).toEqual('path?a=b'); - expect(scope.$location.hashSearch).toEqual({a: 'b'}); - expect(scope.$location.hashPath).toEqual('path'); + $location.updateHash('path', {a: 'b'}); + expect($location.hash).toEqual('path?a=b'); + expect($location.hashSearch).toEqual({a: 'b'}); + expect($location.hashPath).toEqual('path'); }); it('should remove # if hash is empty', function() { - scope.$location.update('http://www.angularjs.org/index.php#'); - expect(scope.$location.href).toEqual('http://www.angularjs.org/index.php'); + $location.update('http://www.angularjs.org/index.php#'); + expect($location.href).toEqual('http://www.angularjs.org/index.php'); }); it('should not change browser\'s url with empty hash', function() { @@ -266,7 +265,7 @@ describe("service", function(){ scope = compile('<input name="price" ng:required ng:validate="number"></input>'); jqLite(document.body).append(scope.$element); scope.$init(); - var $invalidWidgets = scope.$inject('$invalidWidgets'); + var $invalidWidgets = scope.$service('$invalidWidgets'); expect($invalidWidgets.length).toEqual(1); scope.price = 123; @@ -292,19 +291,21 @@ describe("service", function(){ describe("$route", function(){ it('should route and fire change event', function(){ - var log = ''; + var log = '', + $location, $route; + function BookChapter() { this.log = '<init>'; } scope = compile('<div></div>').$init(); - scope.$location = scope.$inject('$location'); - $route = scope.$inject('$route'); + $location = scope.$service('$location'); + $route = scope.$service('$route'); $route.when('/Book/:book/Chapter/:chapter', {controller: BookChapter, template:'Chapter.html'}); $route.when('/Blank'); $route.onChange(function(){ log += 'onChange();'; }); - scope.$location.update('http://server#/Book/Moby/Chapter/Intro?p=123'); + $location.update('http://server#/Book/Moby/Chapter/Intro?p=123'); scope.$eval(); expect(log).toEqual('onChange();'); expect($route.current.params).toEqual({book:'Moby', chapter:'Intro', p:'123'}); @@ -312,14 +313,14 @@ describe("service", function(){ var lastId = $route.current.scope.$id; log = ''; - scope.$location.update('http://server#/Blank?ignore'); + $location.update('http://server#/Blank?ignore'); scope.$eval(); expect(log).toEqual('onChange();'); expect($route.current.params).toEqual({ignore:true}); expect($route.current.scope.$id).not.toEqual(lastId); log = ''; - scope.$location.update('http://server#/NONE'); + $location.update('http://server#/NONE'); scope.$eval(); expect(log).toEqual('onChange();'); expect($route.current).toEqual(null); @@ -330,12 +331,6 @@ describe("service", function(){ }); }); - describe('$resource', function(){ - it('should publish to root scope', function(){ - expect(scope.$inject('$resource')).toBeTruthy(); - }); - }); - describe('$defer', function() { var $defer, $exceptionHandler; @@ -345,9 +340,9 @@ describe("service", function(){ '$exceptionHandler': jasmine.createSpy('$exceptionHandler') }); - $browser = scope.$inject('$browser'); - $defer = scope.$inject('$defer'); - $exceptionHandler = scope.$inject('$exceptionHandler'); + $browser = scope.$service('$browser'); + $defer = scope.$service('$defer'); + $exceptionHandler = scope.$service('$exceptionHandler'); }); @@ -497,7 +492,7 @@ describe("service", function(){ describe('cache', function(){ var cache; - beforeEach(function(){ cache = scope.$inject('$xhr.cache'); }); + beforeEach(function(){ cache = scope.$service('$xhr.cache'); }); it('should cache requests', function(){ $browserXhr.expectGET('/url').respond('first'); @@ -541,7 +536,7 @@ describe("service", function(){ }); it('should keep track of in flight requests and request only once', function(){ - scope.$inject('$xhr.bulk').urls['/bulk'] = { + scope.$service('$xhr.bulk').urls['/bulk'] = { match:function(url){ return url == '/url'; } @@ -611,7 +606,7 @@ describe("service", function(){ $browser = new MockBrowser(); $browser.cookieHash['preexisting'] = 'oldCookie'; scope = createScope(null, angularService, {$browser: $browser}); - scope.$cookies = scope.$inject('$cookies'); + scope.$cookies = scope.$service('$cookies'); }); @@ -709,7 +704,7 @@ describe("service", function(){ describe('$cookieStore', function() { it('should serialize objects to json', function() { - scope.$inject('$cookieStore').put('objectCookie', {id: 123, name: 'blah'}); + scope.$service('$cookieStore').put('objectCookie', {id: 123, name: 'blah'}); scope.$eval(); //force eval in test expect($browser.cookies()).toEqual({'objectCookie': '{"id":123,"name":"blah"}'}); }); @@ -718,12 +713,12 @@ describe("service", function(){ it('should deserialize json to object', function() { $browser.cookies('objectCookie', '{"id":123,"name":"blah"}'); $browser.poll(); - expect(scope.$inject('$cookieStore').get('objectCookie')).toEqual({id: 123, name: 'blah'}); + expect(scope.$service('$cookieStore').get('objectCookie')).toEqual({id: 123, name: 'blah'}); }); it('should delete objects from the store when remove is called', function() { - scope.$inject('$cookieStore').put('gonner', { "I'll":"Be Back"}); + scope.$service('$cookieStore').put('gonner', { "I'll":"Be Back"}); scope.$eval(); //force eval in test expect($browser.cookies()).toEqual({'gonner': '{"I\'ll":"Be Back"}'}); }); diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index cfda67d1..98dd3480 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -551,9 +551,9 @@ describe("widget", function(){ scope.childScope = createScope(); scope.childScope.name = 'misko'; scope.url = 'myUrl'; - scope.$inject('$xhr.cache').data.myUrl = {value:'{{name}}'}; + scope.$service('$xhr.cache').data.myUrl = {value:'{{name}}'}; scope.$init(); - scope.$inject('$browser').defer.flush(); + scope.$service('$browser').defer.flush(); expect(element.text()).toEqual('misko'); dealoc(scope); }); @@ -564,9 +564,9 @@ describe("widget", function(){ scope.childScope = createScope(); scope.childScope.name = 'igor'; scope.url = 'myUrl'; - scope.$inject('$xhr.cache').data.myUrl = {value:'{{name}}'}; + scope.$service('$xhr.cache').data.myUrl = {value:'{{name}}'}; scope.$init(); - scope.$inject('$browser').defer.flush(); + scope.$service('$browser').defer.flush(); expect(element.text()).toEqual('igor'); @@ -581,9 +581,9 @@ describe("widget", function(){ var element = jqLite('<ng:include src="url" scope="this"></ng:include>'); var scope = angular.compile(element); scope.url = 'myUrl'; - scope.$inject('$xhr.cache').data.myUrl = {value:'{{c=c+1}}'}; + scope.$service('$xhr.cache').data.myUrl = {value:'{{c=c+1}}'}; scope.$init(); - scope.$inject('$browser').defer.flush(); + scope.$service('$browser').defer.flush(); // this one should really be just '1', but due to lack of real events things are not working // properly. see discussion at: http://is.gd/ighKk @@ -598,9 +598,9 @@ describe("widget", function(){ expect(scope.loaded).not.toBeDefined(); scope.url = 'myUrl'; - scope.$inject('$xhr.cache').data.myUrl = {value:'my partial'}; + scope.$service('$xhr.cache').data.myUrl = {value:'my partial'}; scope.$init(); - scope.$inject('$browser').defer.flush(); + scope.$service('$browser').defer.flush(); expect(element.text()).toEqual('my partial'); expect(scope.loaded).toBe(true); dealoc(element); |
