diff options
| author | Misko Hevery | 2011-10-17 16:56:56 -0700 |
|---|---|---|
| committer | Misko Hevery | 2011-11-14 16:39:31 -0800 |
| commit | 48697a2b86dbb12ea8de64cc5fece7caf68b321e (patch) | |
| tree | 1fa50659f0bb5de2640dea2a2e5bb5628f2bb14a /test/service/deferSpec.js | |
| parent | 93b777c916ccff243c5a6080bf5f39860ac7bf39 (diff) | |
| download | angular.js-48697a2b86dbb12ea8de64cc5fece7caf68b321e.tar.bz2 | |
refactor(injector): turn scope into a service
- turn scope into a $rootScope service.
- injector is now a starting point for creating angular application.
- added inject() method which wraps jasmine its/beforeEach/afterEach,
and which allows configuration and injection of services.
- refactor tests to use inject() where possible
BREAK:
- removed angular.scope() method
Diffstat (limited to 'test/service/deferSpec.js')
| -rw-r--r-- | test/service/deferSpec.js | 54 |
1 files changed, 23 insertions, 31 deletions
diff --git a/test/service/deferSpec.js b/test/service/deferSpec.js index ff48c93e..98ddeac5 100644 --- a/test/service/deferSpec.js +++ b/test/service/deferSpec.js @@ -1,22 +1,14 @@ 'use strict'; describe('$defer', function() { - var scope, $browser, $defer, $exceptionHandler; - - beforeEach(function() { - scope = angular.scope(angular.service, - {'$exceptionHandler': jasmine.createSpy('$exceptionHandler')}); - $browser = scope.$service('$browser'); - $defer = scope.$service('$defer'); - $exceptionHandler = scope.$service('$exceptionHandler'); - }); - - afterEach(function() { - dealoc(scope); - }); + beforeEach(inject(function(service) { + service('$exceptionHandler', function(){ + return jasmine.createSpy('$exceptionHandler'); + }); + })); - it('should delegate functions to $browser.defer', function() { + it('should delegate functions to $browser.defer', inject(function($defer, $browser, $exceptionHandler) { var counter = 0; $defer(function() { counter++; }); @@ -29,20 +21,20 @@ describe('$defer', function() { expect(counter).toBe(1); expect($exceptionHandler).not.toHaveBeenCalled(); - }); + })); - it('should delegate exception to the $exceptionHandler service', function() { + it('should delegate exception to the $exceptionHandler service', inject(function($defer, $browser, $exceptionHandler) { $defer(function() {throw "Test Error";}); expect($exceptionHandler).not.toHaveBeenCalled(); $browser.defer.flush(); expect($exceptionHandler).toHaveBeenCalledWith("Test Error"); - }); + })); - it('should call $apply after each callback is executed', function() { - var applySpy = this.spyOn(scope, '$apply').andCallThrough(); + it('should call $apply after each callback is executed', inject(function($defer, $browser, $rootScope) { + var applySpy = this.spyOn($rootScope, '$apply').andCallThrough(); $defer(function() {}); expect(applySpy).not.toHaveBeenCalled(); @@ -56,36 +48,36 @@ describe('$defer', function() { $defer(function() {}); $browser.defer.flush(); expect(applySpy.callCount).toBe(2); - }); + })); - it('should call $apply even if an exception is thrown in callback', function() { - var applySpy = this.spyOn(scope, '$apply').andCallThrough(); + it('should call $apply even if an exception is thrown in callback', inject(function($defer, $browser, $rootScope) { + var applySpy = this.spyOn($rootScope, '$apply').andCallThrough(); $defer(function() {throw "Test Error";}); expect(applySpy).not.toHaveBeenCalled(); $browser.defer.flush(); expect(applySpy).toHaveBeenCalled(); - }); + })); - it('should allow you to specify the delay time', function() { + it('should allow you to specify the delay time', inject(function($defer, $browser) { var defer = this.spyOn($browser, 'defer'); $defer(noop, 123); expect(defer.callCount).toEqual(1); expect(defer.mostRecentCall.args[1]).toEqual(123); - }); + })); - it('should return a cancelation token', function() { + it('should return a cancelation token', inject(function($defer, $browser) { var defer = this.spyOn($browser, 'defer').andReturn('xxx'); expect($defer(noop)).toEqual('xxx'); - }); + })); describe('cancel', function() { - it('should cancel tasks', function() { + it('should cancel tasks', inject(function($defer, $browser) { var task1 = jasmine.createSpy('task1'), task2 = jasmine.createSpy('task2'), task3 = jasmine.createSpy('task3'), @@ -102,10 +94,10 @@ describe('$defer', function() { expect(task1).not.toHaveBeenCalled(); expect(task2).toHaveBeenCalledOnce(); expect(task3).not.toHaveBeenCalled(); - }); + })); - it('should return true if a task was succesffuly canceled', function() { + it('should return true if a task was succesffuly canceled', inject(function($defer, $browser) { var task1 = jasmine.createSpy('task1'), task2 = jasmine.createSpy('task2'), token1, token2; @@ -116,6 +108,6 @@ describe('$defer', function() { expect($defer.cancel(token1)).toBe(false); expect($defer.cancel(token2)).toBe(true); - }); + })); }); }); |
