From 78dc213dceec0204a292f11209e37b6d1041d93b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kiss=20R=C3=B3bert?= Date: Thu, 19 Oct 2023 09:44:05 +0200 Subject: [PATCH] fix: don't mutate default options of Seller --- lib/Seller.js | 2 +- tests/seller.spec.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/Seller.js b/lib/Seller.js index 5c31db8..9596014 100644 --- a/lib/Seller.js +++ b/lib/Seller.js @@ -8,7 +8,7 @@ const defaultOptions = { export class Seller { constructor (options) { - this._options = merge.recursive(defaultOptions, options || {}) + this._options = merge.recursive(true, defaultOptions, options || {}) } _generateXML (indentLevel) { diff --git a/tests/seller.spec.js b/tests/seller.spec.js index 1ddcd7b..37d5319 100644 --- a/tests/seller.spec.js +++ b/tests/seller.spec.js @@ -19,6 +19,18 @@ describe('Seller', function () { it('should set _options property', function () { expect(seller).to.have.property('_options').that.is.an('object') }) + + it('should not mutate options', function () { + const seller = new Seller({}) + const expected = { + _options: { + bank: {}, + email: {} + } + } + + expect(seller).to.be.deep.equal(expected) + }) }) describe('_generateXML', function () {