Skip to content

Commit

Permalink
mock: improve validateReplyParameters (#2783)
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak authored Feb 20, 2024
1 parent ff4c57a commit dfe7bbd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/mock/mock-interceptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class MockInterceptor {
if (typeof data === 'undefined') {
throw new InvalidArgumentError('data must be defined')
}
if (typeof responseOptions !== 'object') {
if (typeof responseOptions !== 'object' || responseOptions === null) {
throw new InvalidArgumentError('responseOptions must be an object')
}
}
Expand Down
3 changes: 2 additions & 1 deletion test/mock-interceptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@ describe('MockInterceptor - reply callback', () => {
})

test('should error if passed options invalid', t => {
t = tspl(t, { plan: 2 })
t = tspl(t, { plan: 3 })

const mockInterceptor = new MockInterceptor({
path: '',
method: ''
}, [])
t.throws(() => mockInterceptor.reply(), new InvalidArgumentError('statusCode must be defined'))
t.throws(() => mockInterceptor.reply(200, () => { }, 'hello'), new InvalidArgumentError('responseOptions must be an object'))
t.throws(() => mockInterceptor.reply(200, () => { }, null), new InvalidArgumentError('responseOptions must be an object'))
})
})

Expand Down

0 comments on commit dfe7bbd

Please sign in to comment.