diff --git a/index.js b/index.js index 57350be..db943a3 100644 --- a/index.js +++ b/index.js @@ -68,7 +68,7 @@ mOcKiNgCaSe.log = (input, options) => console.log(mOcKiNgCaSe(input, options)); * @return mOcKiNgCaSe with default options */ mOcKiNgCaSe.config = defaultOptions => (input = "", overridedDefaultOptions) => { - const options = overridedDefaultOptions || defaultOptions; + const options = Object.assign(defaultOptions || {}, overridedDefaultOptions || {}); return mOcKiNgCaSe(input, options); }; diff --git a/mockingcase.test.js b/mockingcase.test.js index d2857cd..072bb79 100644 --- a/mockingcase.test.js +++ b/mockingcase.test.js @@ -132,16 +132,20 @@ describe("mockingcase", () => { }); }); - describe("default options when importing/requering package", () => { + describe("default options when importing/requiring package", () => { test("default options", () => { - const mOcKiNgCaSe = require("./index").config({ onlyLetters: true }); + const mOcKiNgCaSe = require("./index").config({ + onlyLetters: true, + }); const input = "hello123"; const expectedOutput = "hElLo"; expect(mOcKiNgCaSe(input)).toEqual(expectedOutput); }); test("override default options", () => { - const mOcKiNgCaSe = require("./index").config({ onlyLetters: true }); + const mOcKiNgCaSe = require("./index").config({ + onlyLetters: true, + }); const input = "hello123"; const options = { onlyLetters: false, @@ -149,6 +153,19 @@ describe("mockingcase", () => { const expectedOutput = "hElLo123"; expect(mOcKiNgCaSe(input, options)).toEqual(expectedOutput); }); + + test("overriding default options should keep unaffected defaults", () => { + const mOcKiNgCaSe = require("./index").config({ + onlyLetters: true, + firstUpper: true, + }); + const input = "hello123"; + const options = { + onlyLetters: false, + }; + const expectedOutput = "HeLlO123"; + expect(mOcKiNgCaSe(input, options)).toEqual(expectedOutput); + }); }); describe("default input", () => { @@ -158,7 +175,9 @@ describe("mockingcase", () => { }); test("For config option if the input is undefined, an error should be thrown", () => { - const mOcKiNgCaSe = require("./index").config({ onlyLetters: true }); + const mOcKiNgCaSe = require("./index").config({ + onlyLetters: true, + }); const input = undefined; const options = { onlyLetters: false,