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

mock: improve validateReplyParameters #2783

Merged
merged 1 commit into from
Feb 20, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')
}
Comment on lines 106 to 108
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data can never be undefined because it is always set to empty string

const [statusCode, data = '', responseOptions = {}] = [...arguments]

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
Loading