Skip to content

Commit

Permalink
nock#1836 fixes expected Node behaviour for http.get
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethaasan committed Jan 10, 2020
1 parent ad0babd commit 17ad360
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/common.js
Expand Up @@ -99,7 +99,11 @@ function overrideRequests(newRequest) {
}
// https://nodejs.org/api/http.html#http_http_get_options_callback
module.get = function(input, options, callback) {
const req = module.request(input, options, callback)
const req = newRequest(proto, overriddenGet.bind(module), [
input,
options,
callback,
])
req.end()
return req
}
Expand Down
27 changes: 27 additions & 0 deletions tests/test_common.js
Expand Up @@ -512,3 +512,30 @@ test('testing timers are deleted correctly', t => {
t.end()
})
})

test('correct node behavior', t => {
const scope = nock('http://example.test')
.get('/')
.reply()

const reqSpy = sinon.spy(http.request)
const origHttpReq = http.request

http.request = reqSpy

http.get('http://example.test', res => {
t.equal(res.statusCode, 200)

res.on('data', reqSpy)

res.on('end', () => {
t.equal(reqSpy.called, false)
t.end()
})
})

t.on('end', () => {
scope.done()
http.request = origHttpReq
})
})

0 comments on commit 17ad360

Please sign in to comment.