diff options
| author | Igor Minar | 2012-01-04 09:21:05 -0800 |
|---|---|---|
| committer | Vojta Jina | 2012-01-09 13:17:48 -0800 |
| commit | 23f8da7cbb59c8f53f0f5c1e48102faeb4b7fd85 (patch) | |
| tree | c4bc429584921a90da3a9043e21a5dcfa50137e9 /test/service/httpSpec.js | |
| parent | b911e303ecad8b7b54589e26f3c551395bf47405 (diff) | |
| download | angular.js-23f8da7cbb59c8f53f0f5c1e48102faeb4b7fd85.tar.bz2 | |
feat($http): expose req/resp headers to transform fns
Diffstat (limited to 'test/service/httpSpec.js')
| -rw-r--r-- | test/service/httpSpec.js | 53 |
1 files changed, 48 insertions, 5 deletions
diff --git a/test/service/httpSpec.js b/test/service/httpSpec.js index c1f8645e..5efe2954 100644 --- a/test/service/httpSpec.js +++ b/test/service/httpSpec.js @@ -567,6 +567,35 @@ describe('$http', function() { $http({method: 'POST', url: '/url', data: 'string-data'}); }); }); + + + it('should have access to request headers', function() { + $httpBackend.expect('POST', '/url', 'header1').respond(200); + $http.post('/url', 'req', { + headers: {h1: 'header1'}, + transformRequest: function(data, headers) { + return headers('h1'); + } + }).success(callback); + $httpBackend.flush(); + + expect(callback).toHaveBeenCalledOnce(); + }); + + + it('should pipeline more functions', function() { + function first(d, h) {return d + '-first' + ':' + h('h1')} + function second(d) {return uppercase(d)} + + $httpBackend.expect('POST', '/url', 'REQ-FIRST:V1').respond(200); + $http.post('/url', 'req', { + headers: {h1: 'v1'}, + transformRequest: [first, second] + }).success(callback); + $httpBackend.flush(); + + expect(callback).toHaveBeenCalledOnce(); + }); }); @@ -625,16 +654,30 @@ describe('$http', function() { }); + it('should have access to response headers', function() { + $httpBackend.expect('GET', '/url').respond(200, 'response', {h1: 'header1'}); + $http.get('/url', { + transformResponse: function(data, headers) { + return headers('h1'); + } + }).success(callback); + $httpBackend.flush(); + + expect(callback).toHaveBeenCalledOnce(); + expect(callback.mostRecentCall.args[0]).toBe('header1'); + }); + + it('should pipeline more functions', function() { - function first(d) {return d + '1';} - function second(d) {return d + '2';} + function first(d, h) {return d + '-first' + ':' + h('h1')} + function second(d) {return uppercase(d)} - $httpBackend.expect('POST', '/url').respond('0'); - $http({method: 'POST', url: '/url', transformResponse: [first, second]}).success(callback); + $httpBackend.expect('POST', '/url').respond(200, 'resp', {h1: 'v1'}); + $http.post('/url', '', {transformResponse: [first, second]}).success(callback); $httpBackend.flush(); expect(callback).toHaveBeenCalledOnce(); - expect(callback.mostRecentCall.args[0]).toBe('012'); + expect(callback.mostRecentCall.args[0]).toBe('RESP-FIRST:V1'); }); }); }); |
