diff options
| author | Igor Minar | 2011-02-15 01:12:45 -0500 |
|---|---|---|
| committer | Igor Minar | 2011-02-15 11:01:53 -0500 |
| commit | 1777110958f76ee4be5760e36c96702223385918 (patch) | |
| tree | 5aa03b246507e66877e5eac69e58e004e244d7a5 /test/service/deferSpec.js | |
| parent | d2089a16335276eecb8d81eb17332c2dff2cf1a2 (diff) | |
| download | angular.js-1777110958f76ee4be5760e36c96702223385918.tar.bz2 | |
split up services into individual files
- split up services into files under src/service
- split up specs into files under test/service
- rewrite all specs so that they don't depend on one global forEach
- get rid of obsolete code and tests in ng:switch
- rename mock $log spec from "$log" to "$log mock"
Diffstat (limited to 'test/service/deferSpec.js')
| -rw-r--r-- | test/service/deferSpec.js | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/test/service/deferSpec.js b/test/service/deferSpec.js new file mode 100644 index 00000000..932c3661 --- /dev/null +++ b/test/service/deferSpec.js @@ -0,0 +1,69 @@ +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); + }); + + + it('should delegate functions to $browser.defer', function() { + var counter = 0; + $defer(function() { counter++; }); + + expect(counter).toBe(0); + + $browser.defer.flush(); + expect(counter).toBe(1); + + $browser.defer.flush(); //does nothing + expect(counter).toBe(1); + + expect($exceptionHandler).not.toHaveBeenCalled(); + }); + + + it('should delegate exception to the $exceptionHandler service', function() { + $defer(function() {throw "Test Error";}); + expect($exceptionHandler).not.toHaveBeenCalled(); + + $browser.defer.flush(); + expect($exceptionHandler).toHaveBeenCalledWith("Test Error"); + }); + + + it('should call eval after each callback is executed', function() { + var eval = this.spyOn(scope, '$eval').andCallThrough(); + + $defer(function() {}); + expect(eval).wasNotCalled(); + + $browser.defer.flush(); + expect(eval).wasCalled(); + + eval.reset(); //reset the spy; + + $defer(function() {}); + $defer(function() {}); + $browser.defer.flush(); + expect(eval.callCount).toBe(2); + }); + + + it('should call eval even if an exception is thrown in callback', function() { + var eval = this.spyOn(scope, '$eval').andCallThrough(); + + $defer(function() {throw "Test Error";}); + expect(eval).wasNotCalled(); + + $browser.defer.flush(); + expect(eval).wasCalled(); + }); +}); |
