Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(requestoverrider): Add method property to mocked requests #1561

Merged
merged 3 commits into from
May 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/request_overrider.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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')
mrijke marked this conversation as resolved.
Show resolved Hide resolved
scope.done()
t.end()
})
req.end()
})