Skip to content

Commit 4857ae5

Browse files
mrijkepaulmelnikow
authored andcommitted
feat(requestoverrider): Add method property to mocked requests (#1561)
1 parent 900d96d commit 4857ae5

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/request_overrider.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ function RequestOverrider(req, options, interceptors, remove, cb) {
9494
}
9595

9696
req.path = options.path
97+
req.method = options.method
9798

9899
options.getHeader = function(name) {
99100
return getHeader(req, name)

tests/test_request_overrider.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,3 +393,24 @@ test('should throw expected error when creating request with missing options', t
393393
})
394394
t.end()
395395
})
396+
397+
// https://github.com/nock/nock/issues/1558
398+
test("mocked requests have 'method' property", t => {
399+
const scope = nock('http://example.test')
400+
.get('/somepath')
401+
.reply(200, {})
402+
403+
const req = http.request({
404+
host: 'example.test',
405+
path: '/somepath',
406+
method: 'GET',
407+
port: 80,
408+
})
409+
t.equal(req.method, 'GET')
410+
req.on('response', function(res) {
411+
t.equal(res.req.method, 'GET')
412+
scope.done()
413+
t.end()
414+
})
415+
req.end()
416+
})

0 commit comments

Comments
 (0)