-
Notifications
You must be signed in to change notification settings - Fork 27.4k
feat($http): provide a config object as an argument to header functions #10622
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -781,6 +781,34 @@ describe('$http', function() { | |
$httpBackend.flush(); | ||
}); | ||
|
||
it('should expose a config object to header functions', function() { | ||
var config = { | ||
foo: 'Rewritten', | ||
headers: {'Accept': function(config) { | ||
return config.foo; | ||
}} | ||
}; | ||
|
||
$httpBackend.expect('GET', '/url', undefined, {Accept: 'Rewritten'}).respond(''); | ||
$http.get('/url', config); | ||
$httpBackend.flush(); | ||
}); | ||
|
||
it('should not allow modifications to a config object in header functions', function() { | ||
var config = { | ||
headers: {'Accept': function(config) { | ||
config.foo = 'bar'; | ||
return 'Rewritten'; | ||
}} | ||
}; | ||
|
||
$httpBackend.expect('GET', '/url', undefined, {Accept: 'Rewritten'}).respond(''); | ||
$http.get('/url', config); | ||
$httpBackend.flush(); | ||
|
||
expect(config.foo).toBeUndefined(); | ||
}); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we also test the main functionality of this feature? :p There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @caitp it is tested as otherwise a mocked request would fail, no? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let me check ngMock one sec... But in spite of that, I think you should have a different spec for that, because it's not explicitly testing that, it's explicitly testing that the passed in config object is a shallow copy There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, I thought of splitting it into 2 separate specs when I saw your comment. Will create 2 separate specs. |
||
it('should check the cache before checking the XSRF cookie', inject(function($browser, $cacheFactory) { | ||
var testCache = $cacheFactory('testCache'), | ||
executionOrder = []; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should ignore modifications (but no big deal)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will also only "ignore" changes to root properties of the config object, so changes to child object properties won't be ignored :( but I don't think it's worth worrying about it until someone complains
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeh... but I agree that we shouldn't worry about it too much right now...