From 7f72488cca35bde74b35a89099292a8467cd8565 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Garc=C3=ADa?= Date: Fri, 5 Apr 2024 15:32:07 +0200 Subject: [PATCH] fix: return empty string when send was called with undefined --- lib/mockResponse.js | 2 +- test/lib/mockResponse.spec.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/mockResponse.js b/lib/mockResponse.js index f847dd9..9a0c99b 100644 --- a/lib/mockResponse.js +++ b/lib/mockResponse.js @@ -165,7 +165,7 @@ function createResponse(options = {}) { _data = data; } } else { - _data += data; + _data += data || ''; } }; diff --git a/test/lib/mockResponse.spec.js b/test/lib/mockResponse.spec.js index a268738..0e78d5d 100644 --- a/test/lib/mockResponse.spec.js +++ b/test/lib/mockResponse.spec.js @@ -1364,6 +1364,11 @@ describe('mockResponse', () => { expect(response._getData()).to.equal(''); }); + it('should return empty string when sent data is undefined', () => { + response.send(undefined); + expect(response._getData()).to.equal(''); + }); + it('should return sent data', () => { response.send('data'); expect(response._getData()).to.equal('data');