Skip to content

Commit

Permalink
feat: Throw an error on invalid truthy reply status codes (#1571)
Browse files Browse the repository at this point in the history
  • Loading branch information
mastermatt authored and paulmelnikow committed May 28, 2019
1 parent 2444b6b commit de525a1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/interceptor.js
Expand Up @@ -90,7 +90,7 @@ Interceptor.prototype.reply = function reply(statusCode, body, rawHeaders) {
this.statusCode = null
this.fullReplyFunction = statusCode
} else {
if (statusCode && !Number.isInteger(statusCode)) {
if (statusCode !== undefined && !Number.isInteger(statusCode)) {
throw new Error(`Invalid ${typeof statusCode} value for status code`)
}

Expand Down
13 changes: 13 additions & 0 deletions tests/test_reply_body.js
Expand Up @@ -158,3 +158,16 @@ test('reply with missing status code defaults to 200', async t => {
t.equal(body, '')
scope.done()
})

test('reply with invalid status code throws', t => {
const scope = nock('http://localhost').get('/')

t.throws(() => scope.reply('200'), {
message: 'Invalid string value for status code',
})
t.throws(() => scope.reply(false), {
message: 'Invalid boolean value for status code',
})

t.end()
})

0 comments on commit de525a1

Please sign in to comment.