Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #54 #57

Merged
merged 2 commits into from
Sep 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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