Skip to content

Commit

Permalink
Close #54 | Fix mOcKiNgCaSe.config overridedDefaultOptions (#57)
Browse files Browse the repository at this point in the history
* merging default options with override options, fixed typo in tests

* prettier formatted
  • Loading branch information
thunderlorn authored and strdr4605 committed Sep 8, 2019
1 parent 2b8db96 commit 5f10cf6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down
27 changes: 23 additions & 4 deletions mockingcase.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,23 +132,40 @@ 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,
};
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", () => {
Expand All @@ -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,
Expand Down

0 comments on commit 5f10cf6

Please sign in to comment.