Skip to content

Commit

Permalink
Merge pull request #18 from shuvalov-anton/fix-multi-header
Browse files Browse the repository at this point in the history
Fix setting multiple headers at once.
  • Loading branch information
A committed Oct 7, 2015
2 parents 7850897 + d09f07c commit 36ea0c6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ function mock(superagent) {
}
// Recursively set keys if passed an object
if (isObject(key)) {
for (var key in field) {
this.set(key, field[key]);
for (var field in key) {
this.set(field, key[field]);
}
return this;
}
Expand Down
16 changes: 16 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,22 @@ describe('superagent mock', function() {
;
});

it('should support multiple headers', function(done) {
mock.get('/', function(req) {
return req.headers;
});
request.get('/')
.set({
'My-Header': 'my-Value',
'User-Agent': 'Opera Mini',
})
.end(function(_, data) {
data.should.have.property('my-header', 'my-Value')
data.should.have.property('user-agent', 'Opera Mini')
done();
})
})

it('should throw error when header isn\'t a string', function() {
mock.get('/topics/:id', function(req) {
return req.headers;
Expand Down

0 comments on commit 36ea0c6

Please sign in to comment.