diff --git a/index.js b/index.js index 1c71802..7daea87 100644 --- a/index.js +++ b/index.js @@ -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; } diff --git a/test.js b/test.js index 074729d..f47c3bc 100644 --- a/test.js +++ b/test.js @@ -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;