Skip to content

Commit de525a1

Browse files
mastermattpaulmelnikow
authored andcommitted
feat: Throw an error on invalid truthy reply status codes (#1571)
1 parent 2444b6b commit de525a1

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/interceptor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Interceptor.prototype.reply = function reply(statusCode, body, rawHeaders) {
9090
this.statusCode = null
9191
this.fullReplyFunction = statusCode
9292
} else {
93-
if (statusCode && !Number.isInteger(statusCode)) {
93+
if (statusCode !== undefined && !Number.isInteger(statusCode)) {
9494
throw new Error(`Invalid ${typeof statusCode} value for status code`)
9595
}
9696

tests/test_reply_body.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,16 @@ test('reply with missing status code defaults to 200', async t => {
158158
t.equal(body, '')
159159
scope.done()
160160
})
161+
162+
test('reply with invalid status code throws', t => {
163+
const scope = nock('http://localhost').get('/')
164+
165+
t.throws(() => scope.reply('200'), {
166+
message: 'Invalid string value for status code',
167+
})
168+
t.throws(() => scope.reply(false), {
169+
message: 'Invalid boolean value for status code',
170+
})
171+
172+
t.end()
173+
})

0 commit comments

Comments
 (0)