diff options
| author | Karl Seamon | 2011-07-22 15:56:45 -0400 |
|---|---|---|
| committer | Igor Minar | 2011-07-27 15:21:31 -0700 |
| commit | b5594a773a6f07dcba914aa385f92d3305285b24 (patch) | |
| tree | 40823e64e9f74b356a8065edae9bbdf351082164 /test/service/xhr.cacheSpec.js | |
| parent | f39420e7d7aca2a97eaa01853991facf65dcbd6e (diff) | |
| download | angular.js-b5594a773a6f07dcba914aa385f92d3305285b24.tar.bz2 | |
feat($xhr): add custom error callback to $xhr, $xhr.cache, $xhr.bulk, $resource
Closes #408
Diffstat (limited to 'test/service/xhr.cacheSpec.js')
| -rw-r--r-- | test/service/xhr.cacheSpec.js | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/test/service/xhr.cacheSpec.js b/test/service/xhr.cacheSpec.js index 905a9dae..f4654cd4 100644 --- a/test/service/xhr.cacheSpec.js +++ b/test/service/xhr.cacheSpec.js @@ -1,10 +1,10 @@ 'use strict'; describe('$xhr.cache', function() { - var scope, $browser, $browserXhr, cache, log; + var scope, $browser, $browserXhr, $xhrErr, cache, log; - beforeEach(function(){ - scope = angular.scope(); + beforeEach(function() { + scope = angular.scope({}, null, {'$xhr.error': $xhrErr = jasmine.createSpy('$xhr.error')}); $browser = scope.$service('$browser'); $browserXhr = $browser.xhr; cache = scope.$service('$xhr.cache'); @@ -143,4 +143,36 @@ describe('$xhr.cache', function() { $browser.defer.flush(); expect(evalSpy).toHaveBeenCalled(); }); + + it('should call the error callback on error if provided', function() { + var errorSpy = jasmine.createSpy('error'), + successSpy = jasmine.createSpy('success'); + + $browserXhr.expectGET('/url').respond(500, 'error'); + + cache('GET', '/url', null, successSpy, errorSpy, false, true); + $browserXhr.flush(); + expect(errorSpy).toHaveBeenCalledWith(500, 'error'); + expect(successSpy).not.toHaveBeenCalled(); + + errorSpy.reset(); + cache('GET', '/url', successSpy, errorSpy, false, true); + $browserXhr.flush(); + expect(errorSpy).toHaveBeenCalledWith(500, 'error'); + expect(successSpy).not.toHaveBeenCalled(); + }); + + it('should call the $xhr.error on error if error callback not provided', function() { + var errorSpy = jasmine.createSpy('error'), + successSpy = jasmine.createSpy('success'); + + $browserXhr.expectGET('/url').respond(500, 'error'); + cache('GET', '/url', null, successSpy, false, true); + $browserXhr.flush(); + + expect(successSpy).not.toHaveBeenCalled(); + expect($xhrErr).toHaveBeenCalledWith( + {method: 'GET', url: '/url', data: null, success: successSpy}, + {status: 500, body: 'error'}); + }); }); |
