Skip to content

Commit 525493d

Browse files
author
perek
committed
test($http) - add tests for functional header values
Closes angular#5784
1 parent e1cfb19 commit 525493d

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

test/ng/httpSpec.js

+26
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,32 @@ describe('$http', function() {
738738
$httpBackend.flush();
739739
});
740740

741+
it('should override default headers with header function', function() {
742+
$httpBackend.expect('POST', '/url', 'messageBody', function(headers) {
743+
return headers['Accept'] == 'Rewritten' &&
744+
headers['Content-Type'] == 'Rewritten';
745+
}).respond('');
746+
747+
$http({url: '/url', method: 'POST', data: 'messageBody', headers: {
748+
'Accept': 'Rewritten',
749+
'Content-Type': function(){return 'Rewritten';}
750+
}});
751+
$httpBackend.flush();
752+
});
753+
754+
it('should remove default headers with header function', function() {
755+
$httpBackend.expect('POST', '/url', 'messageBody', function(headers) {
756+
return headers['Accept'] == 'Rewritten' &&
757+
typeof headers['Content-Type'] === "undefined";
758+
}).respond('');
759+
760+
$http({url: '/url', method: 'POST', data: 'messageBody', headers: {
761+
'Accept': 'Rewritten',
762+
'Content-Type': function(){return null;}
763+
}});
764+
$httpBackend.flush();
765+
});
766+
741767
it('should override default headers with custom in a case insensitive manner', function() {
742768
$httpBackend.expect('POST', '/url', 'messageBody', function(headers) {
743769
return headers['accept'] == 'Rewritten' &&

0 commit comments

Comments
 (0)