diff options
| author | Igor Minar | 2011-11-30 03:58:34 -0500 |
|---|---|---|
| committer | Igor Minar | 2011-11-30 14:49:35 -0500 |
| commit | 188bdf7768c9594a01a18abae3fa9a3114802508 (patch) | |
| tree | 01116c84c9985f284a7530fa6a15fd8e27453d1b /test | |
| parent | dbd880cc0a9521bd5b9c96ca3f052450c3def336 (diff) | |
| download | angular.js-188bdf7768c9594a01a18abae3fa9a3114802508.tar.bz2 | |
feat($http): add response interceptors
Diffstat (limited to 'test')
| -rw-r--r-- | test/service/httpSpec.js | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/test/service/httpSpec.js b/test/service/httpSpec.js index 63c1f529..3e388a43 100644 --- a/test/service/httpSpec.js +++ b/test/service/httpSpec.js @@ -31,6 +31,51 @@ describe('$http', function() { })); + describe('$httpProvider', function() { + + describe('interceptors', function() { + + it('should default to an empty array', inject(function($httpProvider) { + expect($httpProvider.responseInterceptors).toEqual([]); + })); + + + it('should pass the responses through interceptors', inject(function($httpProvider, $q) { + // just change the response data and pass the response object along + $httpProvider.responseInterceptors.push(function(httpPromise) { + return httpPromise.then(function(response) { + response.data += '!'; + return response; + }); + }); + + // return a new resolved promise representing modified response object + $httpProvider.responseInterceptors.push(function(httpPromise) { + return httpPromise.then(function(response) { + var deferred = $q.defer(); + deferred.resolve({ + data: response.data + '?', + status: 209, + headers: response.headers, + config: response.config + }); + return deferred.promise; + }); + }); + }, function($http, $httpBackend) { + $httpBackend.expect('GET', '/foo').respond(201, 'Hello'); + $http.get('/foo').success(function(data, status) { + expect(data).toBe('Hello!?'); + expect(status).toBe(209); + callback(); + }) + $httpBackend.flush(); + expect(callback).toHaveBeenCalledOnce(); + })); + }); + }); + + it('should do basic request', function() { $httpBackend.expect('GET', '/url').respond(''); $http({url: '/url', method: 'GET'}); |
