From 039d247740fc18b536276de22514a8c28eec1d64 Mon Sep 17 00:00:00 2001 From: uzlopak Date: Tue, 20 Feb 2024 00:18:27 +0100 Subject: [PATCH] mock: improve validateReplyParameters --- lib/mock/mock-interceptor.js | 2 +- test/mock-interceptor.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/mock/mock-interceptor.js b/lib/mock/mock-interceptor.js index 781e477502a..1772f0e424f 100644 --- a/lib/mock/mock-interceptor.js +++ b/lib/mock/mock-interceptor.js @@ -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') } } diff --git a/test/mock-interceptor.js b/test/mock-interceptor.js index 036ea69df98..961a7576dc1 100644 --- a/test/mock-interceptor.js +++ b/test/mock-interceptor.js @@ -53,7 +53,7 @@ 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: '', @@ -61,6 +61,7 @@ describe('MockInterceptor - reply callback', () => { }, []) 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')) }) })