Skip to content

Commit

Permalink
feat(requestoverrider): Add method property to mocked requests (#1561)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrijke authored and paulmelnikow committed May 21, 2019
1 parent 900d96d commit 4857ae5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/request_overrider.js
Expand Up @@ -94,6 +94,7 @@ function RequestOverrider(req, options, interceptors, remove, cb) {
}

req.path = options.path
req.method = options.method

options.getHeader = function(name) {
return getHeader(req, name)
Expand Down
21 changes: 21 additions & 0 deletions tests/test_request_overrider.js
Expand Up @@ -393,3 +393,24 @@ test('should throw expected error when creating request with missing options', t
})
t.end()
})

// https://github.com/nock/nock/issues/1558
test("mocked requests have 'method' property", t => {
const scope = nock('http://example.test')
.get('/somepath')
.reply(200, {})

const req = http.request({
host: 'example.test',
path: '/somepath',
method: 'GET',
port: 80,
})
t.equal(req.method, 'GET')
req.on('response', function(res) {
t.equal(res.req.method, 'GET')
scope.done()
t.end()
})
req.end()
})

0 comments on commit 4857ae5

Please sign in to comment.