diff options
| author | Misko Hevery | 2010-10-08 17:30:13 -0700 |
|---|---|---|
| committer | Misko Hevery | 2010-10-12 16:33:06 -0700 |
| commit | d9abfe8a7e488be8725f56077527b16f7c79546a (patch) | |
| tree | 67089c5d2059e7a56afab0fec19dbce76fdab798 /test | |
| parent | fbfd160316de1b99e7afa4102c7fae2ee5b9c1f5 (diff) | |
| download | angular.js-d9abfe8a7e488be8725f56077527b16f7c79546a.tar.bz2 | |
Introduced injector and $new to scope, and injection into link methods and controllers
- added angular.injector(scope, services, instanceCache) which returns inject
- inject method can return, instance, or call function which have $inject
property
- initialize services with $creation=[eager|eager-publish] this means that
only some of the services are now globally accessible
- upgraded $become on scope to use injector hence respect the $inject property
for injection
- $become should not be run multiple times and will most likely be removed
in future version
- added $new on scope to create a child scope
- $inject is respected on constructor function
- simplified scopes so that they no longer have separate __proto__ for
parent, api, behavior and instance this should speed up execution since
scope will now create one __proto__ chain per scope (not three).
BACKWARD COMPATIBILITY WARNING:
- services now need to have $inject instead of inject property for proper
injection this breaks backward compatibility
- not all services are now published into root scope
(only: $location, $cookie, $window)
- if you have widget/directive which uses services on scope
(such as this.$xhr), you will now have to inject that service in
(as it is not published on the root scope anymore)
Diffstat (limited to 'test')
| -rw-r--r-- | test/InjectorSpec.js | 71 | ||||
| -rw-r--r-- | test/ResourceSpec.js | 20 | ||||
| -rw-r--r-- | test/ScenarioSpec.js | 5 | ||||
| -rw-r--r-- | test/ScopeSpec.js | 75 | ||||
| -rw-r--r-- | test/ValidatorsTest.js | 3 | ||||
| -rw-r--r-- | test/directivesSpec.js | 2 | ||||
| -rw-r--r-- | test/servicesSpec.js | 171 | ||||
| -rw-r--r-- | test/widgetsSpec.js | 4 |
8 files changed, 219 insertions, 132 deletions
diff --git a/test/InjectorSpec.js b/test/InjectorSpec.js new file mode 100644 index 00000000..ba0f27f7 --- /dev/null +++ b/test/InjectorSpec.js @@ -0,0 +1,71 @@ +describe('injector', function(){ + var providers; + var cache; + var inject; + var scope; + + beforeEach(function(){ + providers = extensionMap({}, 'providers'); + cache = {}; + scope = {}; + inject = createInjector(scope, providers, cache); + }); + + it("should return same instance from calling provider", function(){ + providers('text', function(){ return scope.name; }); + scope.name = 'abc'; + expect(inject('text')).toEqual('abc'); + expect(cache.text).toEqual('abc'); + scope.name = 'deleted'; + expect(inject('text')).toEqual('abc'); + }); + + it("should return an array of instances", function(){ + cache.a = 0; + providers('b', function(){return 2;}); + expect(inject(['a', 'b'])).toEqual([0,2]); + }); + + it("should call function", function(){ + providers('a', function(){return 1;}); + providers('b', function(){return 2;}); + var args; + function fn(a, b, c, d) { + args = [this, a, b, c, d]; + } + fn.$inject = ['a', 'b']; + inject(fn, {name:"this"}, 3, 4); + expect(args).toEqual([{name:'this'}, 1, 2, 3, 4]); + }); + + it('should inject providers', function(){ + providers('a', function(){return this.mi = 'Mi';}); + providers('b', function(mi){return this.name = mi+'sko';}, {$inject:['a']}); + expect(inject('b')).toEqual('Misko'); + expect(scope).toEqual({mi:'Mi', name:'Misko'}); + }); + + it('should provide usefull message if no provider', function(){ + assertThrows("Unknown provider for 'idontexist'.", function(){ + inject('idontexist'); + }); + }); + + it('should autostart eager services', function(){ + var log = ''; + providers('eager', function(){log += 'eager;';}, {$creation: 'eager'}); + inject(); + expect(log).toEqual('eager;'); + expect(scope.eager).not.toBeDefined(); + }); + + + it('should return a list of published objects', function(){ + var log = ''; + providers('eager', function(){log += 'eager;'; return 'pub'; }, {$creation: 'eager-published'}); + inject(); + expect(log).toEqual('eager;'); + expect(scope.eager).toEqual('pub'); + + }); +});
\ No newline at end of file diff --git a/test/ResourceSpec.js b/test/ResourceSpec.js index 435176b0..e258d5a3 100644 --- a/test/ResourceSpec.js +++ b/test/ResourceSpec.js @@ -162,26 +162,30 @@ describe("resource", function() { it('should excersize full stack', function(){ var scope = angular.compile('<div></div>'); - var Person = scope.$resource('/Person/:id'); - scope.$browser.xhr.expectGET('/Person/123').respond('\n{\nname:\n"misko"\n}\n'); + var $browser = scope.$inject('$browser'); + var $resource = scope.$inject('$resource'); + var Person = $resource('/Person/:id'); + $browser.xhr.expectGET('/Person/123').respond('\n{\nname:\n"misko"\n}\n'); var person = Person.get({id:123}); - scope.$browser.xhr.flush(); + $browser.xhr.flush(); expect(person.name).toEqual('misko'); }); it('should return the same object when verifying the cache', function(){ var scope = angular.compile('<div></div>'); - var Person = scope.$resource('/Person/:id', null, {query: {method:'GET', isArray: true, verifyCache: true}}); - scope.$browser.xhr.expectGET('/Person/123').respond('[\n{\nname:\n"misko"\n}\n]'); + var $browser = scope.$inject('$browser'); + var $resource = scope.$inject('$resource'); + var Person = $resource('/Person/:id', null, {query: {method:'GET', isArray: true, verifyCache: true}}); + $browser.xhr.expectGET('/Person/123').respond('[\n{\nname:\n"misko"\n}\n]'); var person = Person.query({id:123}); - scope.$browser.xhr.flush(); + $browser.xhr.flush(); expect(person[0].name).toEqual('misko'); - scope.$browser.xhr.expectGET('/Person/123').respond('[\n{\nname:\n"rob"\n}\n]'); + $browser.xhr.expectGET('/Person/123').respond('[\n{\nname:\n"rob"\n}\n]'); var person2 = Person.query({id:123}); expect(person2[0].name).toEqual('misko'); var person2Cache = person2; - scope.$browser.xhr.flush(); + $browser.xhr.flush(); expect(person2Cache).toEqual(person2); expect(person2[0].name).toEqual('rob'); }); diff --git a/test/ScenarioSpec.js b/test/ScenarioSpec.js index ede49a49..730019a2 100644 --- a/test/ScenarioSpec.js +++ b/test/ScenarioSpec.js @@ -43,9 +43,10 @@ describe("ScenarioSpec: configuration", function(){ var url = "http://server/#?book=moby"; var scope = compile("<div>{{$location}}</div>"); var $location = scope.$location; + var $browser = scope.$inject('$browser'); expect($location.hashSearch.book).toBeUndefined(); - scope.$browser.setUrl(url); - scope.$browser.poll(); + $browser.setUrl(url); + $browser.poll(); expect($location.hashSearch.book).toEqual('moby'); }); }); diff --git a/test/ScopeSpec.js b/test/ScopeSpec.js index 66e9d489..4a207bf0 100644 --- a/test/ScopeSpec.js +++ b/test/ScopeSpec.js @@ -1,11 +1,27 @@ describe('scope/model', function(){ + var temp; + + beforeEach(function() { + temp = window.temp = {}; + temp.InjectController = function(exampleService, extra) { + this.localService = exampleService; + this.extra = extra; + this.$root.injectController = this; + }; + temp.InjectController.$inject = ["exampleService"]; + }); + + afterEach(function() { + window.temp = undefined; + }); + it('should create a scope with parent', function(){ var model = createScope({name:'Misko'}); expect(model.name).toEqual('Misko'); }); - it('should have $get/set$/parent$', function(){ + it('should have $get/$set/$parent', function(){ var parent = {}; var model = createScope(parent); model.$set('name', 'adam'); @@ -138,40 +154,6 @@ describe('scope/model', function(){ }); }); - describe('service injection', function(){ - it('should inject services', function(){ - var scope = createScope(null, { - service:function(){ - return "ABC"; - } - }); - expect(scope.service).toEqual("ABC"); - }); - - it('should inject arugments', function(){ - var scope = createScope(null, { - name:function(){ - return "misko"; - }, - greet: extend(function(name) { - return 'hello ' + name; - }, {inject:['name']}) - }); - expect(scope.greet).toEqual("hello misko"); - }); - - it('should throw error on missing dependency', function(){ - try { - createScope(null, { - greet: extend(function(name) { - }, {inject:['name']}) - }); - } catch(e) { - expect(e).toEqual("Don't know how to inject 'name'."); - } - }); - }); - describe('getterFn', function(){ it('should get chain', function(){ expect(getterFn('a.b')(undefined)).toEqual(undefined); @@ -215,4 +197,27 @@ describe('scope/model', function(){ }); }); + describe('$new', function(){ + it('should $new should create new child scope and $become controller', function(){ + var parent = createScope(null, {exampleService: function(){return 'Example Service';}}); + var child = parent.$new(temp.InjectController, 10); + expect(child.localService).toEqual('Example Service'); + expect(child.extra).toEqual(10); + + child.$onEval(function(){ this.run = true; }); + parent.$eval(); + expect(child.run).toEqual(true); + }); + }); + + describe('$become', function(){ + it('should inject properties on controller defined in $inject', function(){ + var parent = createScope(null, {exampleService: function(){return 'Example Service';}}); + var child = createScope(parent); + child.$become(temp.InjectController, 10); + expect(child.localService).toEqual('Example Service'); + expect(child.extra).toEqual(10); + }); + }); + }); diff --git a/test/ValidatorsTest.js b/test/ValidatorsTest.js index 07f3e488..463e05de 100644 --- a/test/ValidatorsTest.js +++ b/test/ValidatorsTest.js @@ -112,6 +112,9 @@ describe('Validator:asynchronous', function(){ if (self.$element) self.$element.remove(); var oldCache = jqCache; jqCache = {}; + if (size(oldCache)) { + dump(oldCache); + } expect(size(oldCache)).toEqual(0); }); diff --git a/test/directivesSpec.js b/test/directivesSpec.js index 42a4879a..d8f04b29 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -282,7 +282,7 @@ describe("directives", function(){ }); it('should support nested controllers', function(){ - temp.ChildGreeter = function() { + temp.ChildGreeter = function(){ this.greeting = 'hey'; this.$root.childGreeter = this; }; diff --git a/test/servicesSpec.js b/test/servicesSpec.js index c0101098..6c586d0a 100644 --- a/test/servicesSpec.js +++ b/test/servicesSpec.js @@ -1,13 +1,19 @@ describe("service", function(){ - var scope, $xhrError, $log, mockServices; + var scope, $xhrError, $log, mockServices, inject, $browser, $browserXhr, $xhrBulk, $xhr, $route; beforeEach(function(){ $xhrError = jasmine.createSpy('$xhr.error'); $log = {}; - scope = createScope(null, angularService, { + scope = createScope({}, angularService, { '$xhr.error': $xhrError, '$log': $log }); + inject = scope.$inject; + $browser = inject('$browser'); + $browserXhr = $browser.xhr; + $xhrBulk = scope.$inject('$xhr.bulk'); + $xhr = scope.$inject('$xhr'); + $route = scope.$inject('$route'); }); afterEach(function(){ @@ -38,7 +44,7 @@ describe("service", function(){ function warn(){ logger+= 'warn;'; } function info(){ logger+= 'info;'; } function error(){ logger+= 'error;'; } - var scope = createScope(null, angularService, {$window: {console:{log:log, warn:warn, info:info, error:error}}, $document:[{cookie:''}]}); + var scope = createScope({}, angularService, {$window: {console:{log:log, warn:warn, info:info, error:error}}, $document:[{cookie:''}]}); scope.$log.log(); scope.$log.warn(); scope.$log.info(); @@ -49,7 +55,7 @@ describe("service", function(){ it('should use console.log if other not present', function(){ var logger = ""; function log(){ logger+= 'log;'; } - var scope = createScope(null, angularService, {$window: {console:{log:log}}, $document:[{cookie:''}]}); + var scope = createScope({}, angularService, {$window: {console:{log:log}}, $document:[{cookie:''}]}); scope.$log.log(); scope.$log.warn(); scope.$log.info(); @@ -58,7 +64,7 @@ describe("service", function(){ }); it('should use noop if no console', function(){ - var scope = createScope(null, angularService, {$window: {}, $document:[{cookie:''}]}); + var scope = createScope({}, angularService, {$window: {}, $document:[{cookie:''}]}); scope.$log.log(); scope.$log.warn(); scope.$log.info(); @@ -182,49 +188,47 @@ describe("service", function(){ function BookChapter() { this.log = '<init>'; } - BookChapter.prototype.init = function(){ - log += 'init();'; - }; var scope = compile('<div></div>').$init(); - scope.$route.when('/Book/:book/Chapter/:chapter', {controller: BookChapter, template:'Chapter.html'}); - scope.$route.when('/Blank'); - scope.$route.onChange(function(){ + var $route = scope.$inject('$route'); + $route.when('/Book/:book/Chapter/:chapter', {controller: BookChapter, template:'Chapter.html'}); + $route.when('/Blank'); + $route.onChange(function(){ log += 'onChange();'; }); scope.$location.parse('http://server#/Book/Moby/Chapter/Intro?p=123'); scope.$eval(); - expect(log).toEqual('onChange();init();'); - expect(scope.$route.current.params).toEqual({book:'Moby', chapter:'Intro', p:'123'}); - expect(scope.$route.current.scope.log).toEqual('<init>'); - var lastId = scope.$route.current.scope.$id; + expect(log).toEqual('onChange();'); + expect($route.current.params).toEqual({book:'Moby', chapter:'Intro', p:'123'}); + expect($route.current.scope.log).toEqual('<init>'); + var lastId = $route.current.scope.$id; log = ''; scope.$location.parse('http://server#/Blank?ignore'); scope.$eval(); expect(log).toEqual('onChange();'); - expect(scope.$route.current.params).toEqual({ignore:true}); - expect(scope.$route.current.scope.$id).not.toEqual(lastId); + expect($route.current.params).toEqual({ignore:true}); + expect($route.current.scope.$id).not.toEqual(lastId); log = ''; scope.$location.parse('http://server#/NONE'); scope.$eval(); expect(log).toEqual('onChange();'); - expect(scope.$route.current).toEqual(null); + expect($route.current).toEqual(null); - scope.$route.when('/NONE', {template:'instant update'}); + $route.when('/NONE', {template:'instant update'}); scope.$eval(); - expect(scope.$route.current.template).toEqual('instant update'); + expect($route.current.template).toEqual('instant update'); }); }); describe('$resource', function(){ it('should publish to root scope', function(){ - expect(scope.$resource).toBeTruthy(); + expect(scope.$inject('$resource')).toBeTruthy(); }); }); describe('$xhr', function(){ - var log, xhr; + var log; function callback(code, response) { expect(code).toEqual(200); log = log + toJson(response) + ';'; @@ -232,27 +236,26 @@ describe("service", function(){ beforeEach(function(){ log = ''; - xhr = scope.$browser.xhr; }); it('should forward the request to $browser and decode JSON', function(){ - xhr.expectGET('/reqGET').respond('first'); - xhr.expectGET('/reqGETjson').respond('["second"]'); - xhr.expectPOST('/reqPOST', {post:'data'}).respond('third'); + $browserXhr.expectGET('/reqGET').respond('first'); + $browserXhr.expectGET('/reqGETjson').respond('["second"]'); + $browserXhr.expectPOST('/reqPOST', {post:'data'}).respond('third'); - scope.$xhr('GET', '/reqGET', null, callback); - scope.$xhr('GET', '/reqGETjson', null, callback); - scope.$xhr('POST', '/reqPOST', {post:'data'}, callback); + $xhr('GET', '/reqGET', null, callback); + $xhr('GET', '/reqGETjson', null, callback); + $xhr('POST', '/reqPOST', {post:'data'}, callback); - xhr.flush(); + $browserXhr.flush(); expect(log).toEqual('"third";["second"];"first";'); }); it('should handle non 200 status codes by forwarding to error handler', function(){ - xhr.expectPOST('/req', 'MyData').respond(500, 'MyError'); - scope.$xhr('POST', '/req', 'MyData', callback); - xhr.flush(); + $browserXhr.expectPOST('/req', 'MyData').respond(500, 'MyError'); + $xhr('POST', '/req', 'MyData', callback); + $browserXhr.flush(); var cb = $xhrError.mostRecentCall.args[0].callback; expect(typeof cb).toEqual($function); expect($xhrError).wasCalledWith( @@ -262,45 +265,45 @@ describe("service", function(){ it('should handle exceptions in callback', function(){ $log.error = jasmine.createSpy('$log.error'); - xhr.expectGET('/reqGET').respond('first'); - scope.$xhr('GET', '/reqGET', null, function(){ throw "MyException"; }); - xhr.flush(); + $browserXhr.expectGET('/reqGET').respond('first'); + $xhr('GET', '/reqGET', null, function(){ throw "MyException"; }); + $browserXhr.flush(); expect($log.error).wasCalledWith("MyException"); }); describe('bulk', function(){ it('should collect requests', function(){ - scope.$xhr.bulk.urls["/"] = {match:/.*/}; - scope.$xhr.bulk('GET', '/req1', null, callback); - scope.$xhr.bulk('POST', '/req2', {post:'data'}, callback); + $xhrBulk.urls["/"] = {match:/.*/}; + $xhrBulk('GET', '/req1', null, callback); + $xhrBulk('POST', '/req2', {post:'data'}, callback); - xhr.expectPOST('/', { + $browserXhr.expectPOST('/', { requests:[{method:'GET', url:'/req1', data: null}, {method:'POST', url:'/req2', data:{post:'data'} }] }).respond([ {status:200, response:'first'}, {status:200, response:'second'} ]); - scope.$xhr.bulk.flush(function(){ log += 'DONE';}); - xhr.flush(); + $xhrBulk.flush(function(){ log += 'DONE';}); + $browserXhr.flush(); expect(log).toEqual('"first";"second";DONE'); }); it('should handle non 200 status code by forwarding to error handler', function(){ - scope.$xhr.bulk.urls['/'] = {match:/.*/}; - scope.$xhr.bulk('GET', '/req1', null, callback); - scope.$xhr.bulk('POST', '/req2', {post:'data'}, callback); + $xhrBulk.urls['/'] = {match:/.*/}; + $xhrBulk('GET', '/req1', null, callback); + $xhrBulk('POST', '/req2', {post:'data'}, callback); - xhr.expectPOST('/', { + $browserXhr.expectPOST('/', { requests:[{method:'GET', url:'/req1', data: null}, {method:'POST', url:'/req2', data:{post:'data'} }] }).respond([ {status:404, response:'NotFound'}, {status:200, response:'second'} ]); - scope.$xhr.bulk.flush(function(){ log += 'DONE';}); - xhr.flush(); + $xhrBulk.flush(function(){ log += 'DONE';}); + $browserXhr.flush(); expect($xhrError).wasCalled(); var cb = $xhrError.mostRecentCall.args[0].callback; @@ -315,29 +318,29 @@ describe("service", function(){ describe('cache', function(){ var cache; - beforeEach(function(){ cache = scope.$xhr.cache; }); + beforeEach(function(){ cache = scope.$inject('$xhr.cache'); }); it('should cache requests', function(){ - xhr.expectGET('/url').respond('first'); + $browserXhr.expectGET('/url').respond('first'); cache('GET', '/url', null, callback); - xhr.flush(); - xhr.expectGET('/url').respond('ERROR'); + $browserXhr.flush(); + $browserXhr.expectGET('/url').respond('ERROR'); cache('GET', '/url', null, callback); - xhr.flush(); + $browserXhr.flush(); expect(log).toEqual('"first";"first";'); cache('GET', '/url', null, callback, false); - xhr.flush(); + $browserXhr.flush(); expect(log).toEqual('"first";"first";"first";'); }); it('should first return cache request, then return server request', function(){ - xhr.expectGET('/url').respond('first'); + $browserXhr.expectGET('/url').respond('first'); cache('GET', '/url', null, callback, true); - xhr.flush(); - xhr.expectGET('/url').respond('ERROR'); + $browserXhr.flush(); + $browserXhr.expectGET('/url').respond('ERROR'); cache('GET', '/url', null, callback, true); expect(log).toEqual('"first";"first";'); - xhr.flush(); + $browserXhr.flush(); expect(log).toEqual('"first";"first";"ERROR";'); }); @@ -350,12 +353,12 @@ describe("service", function(){ }); it('should keep track of in flight requests and request only once', function(){ - scope.$xhr.bulk.urls['/bulk'] = { + scope.$inject('$xhr.bulk').urls['/bulk'] = { match:function(url){ return url == '/url'; } }; - xhr.expectPOST('/bulk', { + $browserXhr.expectPOST('/bulk', { requests:[{method:'GET', url:'/url', data: null}] }).respond([ {status:200, response:'123'} @@ -363,12 +366,12 @@ describe("service", function(){ cache('GET', '/url', null, callback); cache('GET', '/url', null, callback); cache.delegate.flush(); - xhr.flush(); + $browserXhr.flush(); expect(log).toEqual('"123";"123";'); }); it('should clear cache on non GET', function(){ - xhr.expectPOST('abc', {}).respond({}); + $browserXhr.expectPOST('abc', {}).respond({}); cache.data.url = {value:123}; cache('POST', 'abc', {}); expect(cache.data.url).toBeUndefined(); @@ -380,12 +383,12 @@ describe("service", function(){ describe('$cookies', function() { - var scope; + var scope, $browser; beforeEach(function() { - var browser = new MockBrowser(); - browser.cookieHash['preexisting'] = 'oldCookie'; - scope = createScope(null, angularService, {$browser: browser}); + $browser = new MockBrowser(); + $browser.cookieHash['preexisting'] = 'oldCookie'; + scope = createScope(null, angularService, {$browser: $browser}); }); @@ -393,19 +396,19 @@ describe("service", function(){ function(){ expect(scope.$cookies).toEqual({'preexisting': 'oldCookie'}); - // access internal cookie storage of the browser mock directly to simulate behavior of + // access internal cookie storage of the browser mock directly to simulate behavior of // document.cookie - scope.$browser.cookieHash['brandNew'] = 'cookie'; - scope.$browser.poll(); + $browser.cookieHash['brandNew'] = 'cookie'; + $browser.poll(); expect(scope.$cookies).toEqual({'preexisting': 'oldCookie', 'brandNew':'cookie'}); - scope.$browser.cookieHash['brandNew'] = 'cookie2'; - scope.$browser.poll(); + $browser.cookieHash['brandNew'] = 'cookie2'; + $browser.poll(); expect(scope.$cookies).toEqual({'preexisting': 'oldCookie', 'brandNew':'cookie2'}); - delete scope.$browser.cookieHash['brandNew']; - scope.$browser.poll(); + delete $browser.cookieHash['brandNew']; + $browser.poll(); expect(scope.$cookies).toEqual({'preexisting': 'oldCookie'}); }); @@ -414,13 +417,13 @@ describe("service", function(){ scope.$cookies.oatmealCookie = 'nom nom'; scope.$eval(); - expect(scope.$browser.cookies()). + expect($browser.cookies()). toEqual({'preexisting': 'oldCookie', 'oatmealCookie':'nom nom'}); scope.$cookies.oatmealCookie = 'gone'; scope.$eval(); - expect(scope.$browser.cookies()). + expect($browser.cookies()). toEqual({'preexisting': 'oldCookie', 'oatmealCookie': 'gone'}); }); @@ -428,7 +431,7 @@ describe("service", function(){ it('should ignore non-string values when asked to create a cookie', function() { scope.$cookies.nonString = [1, 2, 3]; scope.$eval(); - expect(scope.$browser.cookies()).toEqual({'preexisting': 'oldCookie'}); + expect($browser.cookies()).toEqual({'preexisting': 'oldCookie'}); expect(scope.$cookies).toEqual({'preexisting': 'oldCookie'}); }); @@ -438,21 +441,21 @@ describe("service", function(){ scope.$cookies.undefVal = undefined; scope.$eval(); - expect(scope.$browser.cookies()).toEqual({'preexisting': 'oldCookie'}); + expect($browser.cookies()).toEqual({'preexisting': 'oldCookie'}); }); it('should remove a cookie when a $cookies property is deleted', function() { scope.$cookies.oatmealCookie = 'nom nom'; scope.$eval(); - scope.$browser.poll(); - expect(scope.$browser.cookies()). + $browser.poll(); + expect($browser.cookies()). toEqual({'preexisting': 'oldCookie', 'oatmealCookie':'nom nom'}); delete scope.$cookies.oatmealCookie; scope.$eval(); - expect(scope.$browser.cookies()).toEqual({'preexisting': 'oldCookie'}); + expect($browser.cookies()).toEqual({'preexisting': 'oldCookie'}); }); @@ -485,13 +488,13 @@ describe("service", function(){ it('should serialize objects to json', function() { scope.$cookieStore.put('objectCookie', {id: 123, name: 'blah'}); scope.$eval(); //force eval in test - expect(scope.$browser.cookies()).toEqual({'objectCookie': '{"id":123,"name":"blah"}'}); + expect($browser.cookies()).toEqual({'objectCookie': '{"id":123,"name":"blah"}'}); }); it('should deserialize json to object', function() { - scope.$browser.cookies('objectCookie', '{"id":123,"name":"blah"}'); - scope.$browser.poll(); + $browser.cookies('objectCookie', '{"id":123,"name":"blah"}'); + $browser.poll(); expect(scope.$cookieStore.get('objectCookie')).toEqual({id: 123, name: 'blah'}); }); @@ -499,7 +502,7 @@ describe("service", function(){ it('should delete objects from the store when remove is called', function() { scope.$cookieStore.put('gonner', { "I'll":"Be Back"}); scope.$eval(); //force eval in test - expect(scope.$browser.cookies()).toEqual({'gonner': '{"I\'ll":"Be Back"}'}); + expect($browser.cookies()).toEqual({'gonner': '{"I\'ll":"Be Back"}'}); }); }); diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index 80acc928..8f6ccaea 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -476,7 +476,7 @@ describe("widget", function(){ scope.childScope = createScope(); scope.childScope.name = 'misko'; scope.url = 'myUrl'; - scope.$xhr.cache.data.myUrl = {value:'{{name}}'}; + scope.$inject('$xhr.cache').data.myUrl = {value:'{{name}}'}; scope.$init(); expect(element.text()).toEqual('misko'); }); @@ -487,7 +487,7 @@ describe("widget", function(){ scope.childScope = createScope(); scope.childScope.name = 'igor'; scope.url = 'myUrl'; - scope.$xhr.cache.data.myUrl = {value:'{{name}}'}; + scope.$inject('$xhr.cache').data.myUrl = {value:'{{name}}'}; scope.$init(); expect(element.text()).toEqual('igor'); |
