diff --git a/.eslintrc b/.eslintrc index 59c089d..16c814d 100644 --- a/.eslintrc +++ b/.eslintrc @@ -10,7 +10,19 @@ "jest": true }, "rules": { - "semi": ["error", "always"] + "semi": ["error", "always"], + "unicorn/filename-case": ["error", { "case": "camelCase" }], + "unicorn/catch-error-name": ["error", { "caughtErrorsIgnorePattern": "^(e|error)$" }], + "unicorn/prevent-abbreviations": [ + "error", + { + "whitelist": { + "e": true, + "args": true, + "obj": true + } + } + ] }, - "extends": ["eslint:recommended", "prettier"] -} \ No newline at end of file + "extends": ["eslint:recommended", "plugin:prettier/recommended", "plugin:unicorn/recommended"] +} diff --git a/.huskyrc b/.huskyrc index 276f87c..643bb90 100644 --- a/.huskyrc +++ b/.huskyrc @@ -1,6 +1,5 @@ { "hooks": { - "pre-commit": "lint-staged && npm run test", - "pre-push": "lint-staged && npm run test" + "pre-commit": "lint-staged" } } diff --git a/.lintstagedrc b/.lintstagedrc index cf3e3f6..f89dc44 100644 --- a/.lintstagedrc +++ b/.lintstagedrc @@ -1,3 +1,3 @@ { - "*.js": ["npx eslint --fix", "npx prettier --write", "git add"] + "*.js": ["npx eslint", "git add"] } diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..6d56eb8 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,3 @@ +.vscode +node_modules +coverage \ No newline at end of file diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..90aea8b --- /dev/null +++ b/.prettierrc @@ -0,0 +1,5 @@ +{ + "printWidth": 120, + "useTabs": true, + "tabWidth": 4 +} \ No newline at end of file diff --git a/__tests__/.eslintrc b/__tests__/.eslintrc new file mode 100644 index 0000000..f7e68b9 --- /dev/null +++ b/__tests__/.eslintrc @@ -0,0 +1,33 @@ +{ + "parserOptions": { + "ecmaVersion": 2017, + "sourceType": "module" + }, + "env": { + "es6": true, + "browser": true, + "node": true, + "jest": true + }, + "rules": { + "semi": ["error", "always"], + "unicorn/filename-case": ["error", { "case": "camelCase" }], + "unicorn/catch-error-name": ["error", { "caughtErrorsIgnorePattern": "^(e|error)$" }], + "unicorn/prevent-abbreviations": [ + "error", + { + "whitelist": { + "e": true, + "args": true, + "obj": true + } + } + ] + }, + "extends": [ + "eslint:recommended", + "plugin:prettier/recommended", + "plugin:unicorn/recommended", + "plugin:jest/recommended" + ] +} diff --git a/__tests__/acatch.js b/__tests__/acatch.js index 1f11c3f..7776f2c 100644 --- a/__tests__/acatch.js +++ b/__tests__/acatch.js @@ -13,8 +13,8 @@ describe("acatch tests", () => { const catchInCatchBlockFn = getMockFn(jest)(() => input * 17, "catchInCatchBlockFn"); const result = await acatch(catchFn)(input).catch(catchInCatchBlockFn); expect(result).toBe(input); - expect(catchFn).not.toBeCalled(); - expect(catchInCatchBlockFn).not.toBeCalled(); + expect(catchFn).not.toHaveBeenCalled(); + expect(catchInCatchBlockFn).not.toHaveBeenCalled(); }); it("should work for case with promise on input without reject", async () => { expect.assertions(6); @@ -26,8 +26,8 @@ describe("acatch tests", () => { expect(result).toBe(8); mockFnExpectations(increment, 1, 8, input); expect(increment).toHaveBeenCalledTimes(1); - expect(catchFn).not.toBeCalled(); - expect(catchInCatchBlockFn).not.toBeCalled(); + expect(catchFn).not.toHaveBeenCalled(); + expect(catchInCatchBlockFn).not.toHaveBeenCalled(); }); it("should catch for case with rejected promise on input", async () => { expect.assertions(6); @@ -37,10 +37,10 @@ describe("acatch tests", () => { const catchInCatchBlockFn = getMockFn(jest)(() => input * 17, "catchInCatchBlockFn"); const result = await acatch(catchFn)(createAsyncPromise(increment, false)(input)).catch(catchInCatchBlockFn); expect(result).toBe(28); - expect(increment).not.toBeCalled(); + expect(increment).not.toHaveBeenCalled(); mockFnExpectations(catchFn, 1, 28, getError(input)); expect(catchFn).toHaveBeenCalledTimes(1); - expect(catchInCatchBlockFn).not.toBeCalled(); + expect(catchInCatchBlockFn).not.toHaveBeenCalled(); }); it("should work for reject in promise on input and promise in fallback", async () => { expect.assertions(6); @@ -52,10 +52,10 @@ describe("acatch tests", () => { catchInCatchBlockFn ); expect(result).toBe(28); - expect(increment).not.toBeCalled(); + expect(increment).not.toHaveBeenCalled(); mockFnExpectations(catchFn, 1, 28, getError(input)); expect(catchFn).toHaveBeenCalledTimes(1); - expect(catchInCatchBlockFn).not.toBeCalled(); + expect(catchInCatchBlockFn).not.toHaveBeenCalled(); }); it("should reject for rejection in fallback function", async () => { expect.assertions(6); @@ -67,8 +67,8 @@ describe("acatch tests", () => { createSyncPromise(increment, false)(input) ).catch(catchInCatchBlockFn); expect(result).toBe(119); - expect(increment).not.toBeCalled(); - expect(catchFn).not.toBeCalled(); + expect(increment).not.toHaveBeenCalled(); + expect(catchFn).not.toHaveBeenCalled(); mockFnExpectations(catchInCatchBlockFn, 1, 119, getError(getError(input))); expect(catchInCatchBlockFn).toHaveBeenCalledTimes(1); }); @@ -83,8 +83,8 @@ describe("acatch in acompose tests", () => { const catchInCatchBlockFn = getMockFn(jest)(() => input * 17, "catchInCatchBlockFn"); const result = await acompose(acatch(catchFn), increment2, increment1)(input).catch(catchInCatchBlockFn); expect(result).toBe(9); - expect(catchFn).not.toBeCalled(); - expect(catchInCatchBlockFn).not.toBeCalled(); + expect(catchFn).not.toHaveBeenCalled(); + expect(catchInCatchBlockFn).not.toHaveBeenCalled(); }); it("should work for case with reject in acompose chain", async () => { expect.assertions(9); @@ -98,12 +98,12 @@ describe("acatch in acompose tests", () => { expect(result).toBe(28); expect(catchFn).toHaveBeenCalledTimes(1); mockFnExpectations(catchFn, 1, 28, getError(input + 1)); - expect(catchInCatchBlockFn).not.toBeCalled(); - expect(increment2).not.toBeCalled(); + expect(catchInCatchBlockFn).not.toHaveBeenCalled(); + expect(increment2).not.toHaveBeenCalled(); expect(increment1).toHaveBeenCalledTimes(1); mockFnExpectations(increment1, 1, 8, input); }); - it("should work for case with reject in acompose chain", async () => { + it("should work for case with reject in acompose chain for first argument", async () => { expect.assertions(7); const input = 7; const increment1 = incrementMock(jest, "increment1"); @@ -115,9 +115,9 @@ describe("acatch in acompose tests", () => { expect(result).toBe(28); expect(catchFn).toHaveBeenCalledTimes(1); mockFnExpectations(catchFn, 1, 28, getError(input)); - expect(catchInCatchBlockFn).not.toBeCalled(); - expect(increment1).not.toBeCalled(); - expect(increment2).not.toBeCalled(); + expect(catchInCatchBlockFn).not.toHaveBeenCalled(); + expect(increment1).not.toHaveBeenCalled(); + expect(increment2).not.toHaveBeenCalled(); }); it("should work for case with reject in input", async () => { expect.assertions(7); @@ -134,9 +134,9 @@ describe("acatch in acompose tests", () => { expect(result).toBe(28); expect(catchFn).toHaveBeenCalledTimes(1); mockFnExpectations(catchFn, 1, 28, getError(input)); - expect(increment1).not.toBeCalled(); - expect(increment2).not.toBeCalled(); - expect(catchInCatchBlockFn).not.toBeCalled(); + expect(increment1).not.toHaveBeenCalled(); + expect(increment2).not.toHaveBeenCalled(); + expect(catchInCatchBlockFn).not.toHaveBeenCalled(); }); it("should work for case with reject in acompose chain and acatch in middle", async () => { expect.assertions(8); @@ -149,8 +149,8 @@ describe("acatch in acompose tests", () => { const result = await acompose(increment2, acatch(catchFn), increment1Promise)(input).catch(catchInCatchBlockFn); expect(result).toBe(29); mockFnExpectations(catchFn, 1, 28, getError(input)); - expect(catchInCatchBlockFn).not.toBeCalled(); - expect(increment1).not.toBeCalled(); + expect(catchInCatchBlockFn).not.toHaveBeenCalled(); + expect(increment1).not.toHaveBeenCalled(); expect(increment2).toHaveBeenCalledTimes(1); mockFnExpectations(increment2, 1, 29, 28); }); @@ -165,8 +165,8 @@ describe("acatch in apipe tests", () => { const catchInCatchBlockFn = getMockFn(jest)(() => input * 17, "catchInCatchBlockFn"); const result = await apipe(increment1, increment2, acatch(catchFn))(input).catch(catchInCatchBlockFn); expect(result).toBe(9); - expect(catchFn).not.toBeCalled(); - expect(catchInCatchBlockFn).not.toBeCalled(); + expect(catchFn).not.toHaveBeenCalled(); + expect(catchInCatchBlockFn).not.toHaveBeenCalled(); }); it("should work for case with reject in apipe chain", async () => { expect.assertions(9); @@ -180,12 +180,12 @@ describe("acatch in apipe tests", () => { expect(result).toBe(28); expect(catchFn).toHaveBeenCalledTimes(1); mockFnExpectations(catchFn, 1, 28, getError(input + 1)); - expect(catchInCatchBlockFn).not.toBeCalled(); - expect(increment2).not.toBeCalled(); + expect(catchInCatchBlockFn).not.toHaveBeenCalled(); + expect(increment2).not.toHaveBeenCalled(); expect(increment1).toHaveBeenCalledTimes(1); mockFnExpectations(increment1, 1, 8, input); }); - it("should work for case with reject in apipe chain", async () => { + it("should work for case with reject in apipe chain for first argument", async () => { expect.assertions(7); const input = 7; const increment1 = incrementMock(jest, "increment1"); @@ -197,9 +197,9 @@ describe("acatch in apipe tests", () => { expect(result).toBe(28); expect(catchFn).toHaveBeenCalledTimes(1); mockFnExpectations(catchFn, 1, 28, getError(input)); - expect(catchInCatchBlockFn).not.toBeCalled(); - expect(increment1).not.toBeCalled(); - expect(increment2).not.toBeCalled(); + expect(catchInCatchBlockFn).not.toHaveBeenCalled(); + expect(increment1).not.toHaveBeenCalled(); + expect(increment2).not.toHaveBeenCalled(); }); it("should work for case with reject in input", async () => { expect.assertions(7); @@ -216,9 +216,9 @@ describe("acatch in apipe tests", () => { expect(result).toBe(28); expect(catchFn).toHaveBeenCalledTimes(1); mockFnExpectations(catchFn, 1, 28, getError(input)); - expect(increment1).not.toBeCalled(); - expect(increment2).not.toBeCalled(); - expect(catchInCatchBlockFn).not.toBeCalled(); + expect(increment1).not.toHaveBeenCalled(); + expect(increment2).not.toHaveBeenCalled(); + expect(catchInCatchBlockFn).not.toHaveBeenCalled(); }); it("should work for case with reject in apipe chain and acatch in middle", async () => { expect.assertions(8); @@ -231,8 +231,8 @@ describe("acatch in apipe tests", () => { const result = await apipe(increment1Promise, acatch(catchFn), increment2)(input).catch(catchInCatchBlockFn); expect(result).toBe(29); mockFnExpectations(catchFn, 1, 28, getError(input)); - expect(catchInCatchBlockFn).not.toBeCalled(); - expect(increment1).not.toBeCalled(); + expect(catchInCatchBlockFn).not.toHaveBeenCalled(); + expect(increment1).not.toHaveBeenCalled(); expect(increment2).toHaveBeenCalledTimes(1); mockFnExpectations(increment2, 1, 29, 28); }); diff --git a/__tests__/acompose.js b/__tests__/acompose.js index 8dcd8c9..f3d19be 100644 --- a/__tests__/acompose.js +++ b/__tests__/acompose.js @@ -225,7 +225,7 @@ describe("Tests for asynchronous compose utility", () => { expect(e).toBeInstanceOf(Error); expect(e.message).toBe(getErrorMessage(inputValue)); expect(increment).not.toHaveBeenCalled(); - expect(thenHandler).not.toBeCalled(); + expect(thenHandler).not.toHaveBeenCalled(); }); }); it("should reject properly with rejection in one of the compose functions traditional way", () => { @@ -243,7 +243,7 @@ describe("Tests for asynchronous compose utility", () => { mockFnExpectations(increment, 1, 5, inputValue); mockFnArgumentsExpectations(undefinedErrorFn, 1, 5); expect(incrementInCompose).not.toHaveBeenCalled(); - expect(thenHandler).not.toBeCalled(); + expect(thenHandler).not.toHaveBeenCalled(); }); }); }); diff --git a/__tests__/apipe.js b/__tests__/apipe.js index a4f674e..7410cd2 100644 --- a/__tests__/apipe.js +++ b/__tests__/apipe.js @@ -225,7 +225,7 @@ describe("Tests for asynchronous pipe utility", () => { expect(e).toBeInstanceOf(Error); expect(e.message).toBe(getErrorMessage(inputValue)); expect(increment).not.toHaveBeenCalled(); - expect(thenHandler).not.toBeCalled(); + expect(thenHandler).not.toHaveBeenCalled(); }); }); it("should reject properly with rejection in one of the pipe functions traditional way", () => { @@ -243,7 +243,7 @@ describe("Tests for asynchronous pipe utility", () => { mockFnExpectations(increment, 1, 5, inputValue); mockFnArgumentsExpectations(undefinedErrorFn, 1, 5); expect(incrementInCompose).not.toHaveBeenCalled(); - expect(thenHandler).not.toBeCalled(); + expect(thenHandler).not.toHaveBeenCalled(); }); }); }); diff --git a/__tests__/applyFns.js b/__tests__/applyFns.js index 19bbf7f..29d2c28 100644 --- a/__tests__/applyFns.js +++ b/__tests__/applyFns.js @@ -57,7 +57,7 @@ describe("A kind of composable Promise.all with single input value for all handl await applyFns()(createAsyncPromise(square, false)(inputValue)); expect(true).toBe(false); } catch (e) { - expect(square).not.toBeCalled(); + expect(square).not.toHaveBeenCalled(); expect(e).toBeInstanceOf(Error); expect(e.message).toBe(getErrorMessage(inputValue)); } @@ -76,11 +76,9 @@ describe("A kind of composable Promise.all with single input value for all handl const increment = incrementMock(jest); const concatenateTestString = concatenateTestStringMock(jest); const inputValue = 5; - const result = await applyFns( - createSyncPromise(square), - increment, - createAsyncPromise(concatenateTestString) - )(inputValue); + const result = await applyFns(createSyncPromise(square), increment, createAsyncPromise(concatenateTestString))( + inputValue + ); expect(result).toEqual([25, 6, "5test"]); mockFnExpectations(square, 1, 25, inputValue); mockFnExpectations(increment, 1, 6, inputValue); @@ -187,10 +185,10 @@ describe("A kind of composable Promise.all with single input value for all handl createAsyncPromise(square, false)(inputValue) ); } catch (e) { - expect(squareInAll).not.toBeCalled(); - expect(increment).not.toBeCalled(); - expect(concatenateTestString).not.toBeCalled(); - expect(square).not.toBeCalled(); + expect(squareInAll).not.toHaveBeenCalled(); + expect(increment).not.toHaveBeenCalled(); + expect(concatenateTestString).not.toHaveBeenCalled(); + expect(square).not.toHaveBeenCalled(); expect(e).toBeInstanceOf(Error); expect(e.message).toBe(getErrorMessage(inputValue)); } @@ -208,13 +206,13 @@ describe("A kind of composable Promise.all with single input value for all handl ) .then(thenHandler) .catch(e => { - expect(squareInAll).not.toBeCalled(); - expect(increment).not.toBeCalled(); - expect(concatenateTestString).not.toBeCalled(); - expect(square).not.toBeCalled(); + expect(squareInAll).not.toHaveBeenCalled(); + expect(increment).not.toHaveBeenCalled(); + expect(concatenateTestString).not.toHaveBeenCalled(); + expect(square).not.toHaveBeenCalled(); expect(e).toBeInstanceOf(Error); expect(e.message).toBe(getErrorMessage(inputValue)); - expect(thenHandler).not.toBeCalled(); + expect(thenHandler).not.toHaveBeenCalled(); }); }); it("should reject for error function and promise as input value", async () => { @@ -238,7 +236,7 @@ describe("A kind of composable Promise.all with single input value for all handl mockFnExpectations(square, 1, 25, inputValue); mockFnExpectations(squareInAll, 1, 625, 25); mockFnExpectations(increment, 1, 26, 25); - expect(concatenateTestString).not.toBeCalled(); + expect(concatenateTestString).not.toHaveBeenCalled(); } }); it("should reject for error function and promise as input value classic way", () => { @@ -263,8 +261,8 @@ describe("A kind of composable Promise.all with single input value for all handl mockFnExpectations(square, 1, 25, inputValue); mockFnExpectations(squareInAll, 1, 625, 25); mockFnExpectations(increment, 1, 26, 25); - expect(concatenateTestString).not.toBeCalled(); - expect(thenHandler).not.toBeCalled(); + expect(concatenateTestString).not.toHaveBeenCalled(); + expect(thenHandler).not.toHaveBeenCalled(); }); }); it("should reject for rejected promise in parameters and promise as input value", async () => { @@ -284,9 +282,9 @@ describe("A kind of composable Promise.all with single input value for all handl expect(e.message).toBe(getErrorMessage(25)); mockFnExpectations(square, 1, 25, inputValue); mockFnExpectations(rejectedPromiseFunc, 1, expect.any(Promise), 25); - expect(squareInAll).not.toBeCalled(); + expect(squareInAll).not.toHaveBeenCalled(); mockFnExpectations(increment, 1, 26, 25); - expect(concatenateTestString).not.toBeCalled(); + expect(concatenateTestString).not.toHaveBeenCalled(); } }); it("should reject for rejected promise in parameters and promise as input value classic way", () => { @@ -307,10 +305,10 @@ describe("A kind of composable Promise.all with single input value for all handl expect(e.message).toBe(getErrorMessage(25)); mockFnExpectations(square, 1, 25, inputValue); mockFnExpectations(rejectedPromiseFunc, 1, expect.any(Promise), 25); - expect(squareInAll).not.toBeCalled(); + expect(squareInAll).not.toHaveBeenCalled(); mockFnExpectations(increment, 1, 26, 25); - expect(concatenateTestString).not.toBeCalled(); - expect(thenHandler).not.toBeCalled(); + expect(concatenateTestString).not.toHaveBeenCalled(); + expect(thenHandler).not.toHaveBeenCalled(); }); }); }); diff --git a/__tests__/applySafe.js b/__tests__/applySafe.js index 19ef473..61dbdc4 100644 --- a/__tests__/applySafe.js +++ b/__tests__/applySafe.js @@ -16,8 +16,8 @@ describe("applySafe tests", () => { expect(result).toBe(49); mockFnExpectations(square, 1, 49, input); expect(square).toHaveBeenCalledTimes(1); - expect(fallbackFn).not.toBeCalled(); - expect(catchFn).not.toBeCalled(); + expect(fallbackFn).not.toHaveBeenCalled(); + expect(catchFn).not.toHaveBeenCalled(); }); it("should work for case with promise on input", async () => { expect.assertions(9); @@ -32,8 +32,8 @@ describe("applySafe tests", () => { expect(square).toHaveBeenCalledTimes(1); mockFnExpectations(increment, 1, 8, input); expect(increment).toHaveBeenCalledTimes(1); - expect(fallbackFn).not.toBeCalled(); - expect(catchFn).not.toBeCalled(); + expect(fallbackFn).not.toHaveBeenCalled(); + expect(catchFn).not.toHaveBeenCalled(); }); it("should catch for case with rejected promise on input", async () => { expect.assertions(7); @@ -44,11 +44,11 @@ describe("applySafe tests", () => { const catchFn = getMockFn(jest)(() => input * 17, "catchFn"); const result = await applySafe(square, fallbackFn)(createAsyncPromise(increment, false)(input)).catch(catchFn); expect(result).toBe(28); - expect(increment).not.toBeCalled(); - expect(square).not.toBeCalled(); + expect(increment).not.toHaveBeenCalled(); + expect(square).not.toHaveBeenCalled(); mockFnExpectations(fallbackFn, 1, 28, getError(input)); expect(fallbackFn).toHaveBeenCalledTimes(1); - expect(catchFn).not.toBeCalled(); + expect(catchFn).not.toHaveBeenCalled(); }); it("should work for promises", async () => { expect.assertions(9); @@ -65,8 +65,8 @@ describe("applySafe tests", () => { expect(square).toHaveBeenCalledTimes(1); mockFnExpectations(increment, 1, 8, input); expect(increment).toHaveBeenCalledTimes(1); - expect(fallbackFn).not.toBeCalled(); - expect(catchFn).not.toBeCalled(); + expect(fallbackFn).not.toHaveBeenCalled(); + expect(catchFn).not.toHaveBeenCalled(); }); it("should work for reject in promise in applySafe param", async () => { expect.assertions(9); @@ -81,10 +81,10 @@ describe("applySafe tests", () => { expect(result).toBe(28); mockFnExpectations(increment, 1, 8, input); expect(increment).toHaveBeenCalledTimes(1); - expect(square).not.toBeCalled(); + expect(square).not.toHaveBeenCalled(); mockFnExpectations(fallbackFn, 1, 28, getError(8)); expect(fallbackFn).toHaveBeenCalledTimes(1); - expect(catchFn).not.toBeCalled(); + expect(catchFn).not.toHaveBeenCalled(); }); it("should work for reject in promise in applySafe param and promise in fallback", async () => { expect.assertions(9); @@ -99,10 +99,10 @@ describe("applySafe tests", () => { expect(result).toBe(28); mockFnExpectations(increment, 1, 8, input); expect(increment).toHaveBeenCalledTimes(1); - expect(square).not.toBeCalled(); + expect(square).not.toHaveBeenCalled(); mockFnExpectations(fallbackFn, 1, 28, getError(8)); expect(fallbackFn).toHaveBeenCalledTimes(1); - expect(catchFn).not.toBeCalled(); + expect(catchFn).not.toHaveBeenCalled(); }); it("should reject for rejection in fallback function", async () => { expect.assertions(9); @@ -117,8 +117,8 @@ describe("applySafe tests", () => { expect(result).toBe(119); mockFnExpectations(increment, 1, 8, input); expect(increment).toHaveBeenCalledTimes(1); - expect(square).not.toBeCalled(); - expect(fallbackFn).not.toBeCalled(); + expect(square).not.toHaveBeenCalled(); + expect(fallbackFn).not.toHaveBeenCalled(); mockFnExpectations(catchFn, 1, 119, getError(getError(8))); expect(catchFn).toHaveBeenCalledTimes(1); }); @@ -136,8 +136,8 @@ describe("applySafe in acompose tests", () => { catchInCatchBlockFn ); expect(result).toBe(10); - expect(catchFn).not.toBeCalled(); - expect(catchInCatchBlockFn).not.toBeCalled(); + expect(catchFn).not.toHaveBeenCalled(); + expect(catchInCatchBlockFn).not.toHaveBeenCalled(); expect(increment1).toHaveBeenCalledTimes(1); mockFnExpectations(increment1, 1, 8, input); expect(increment2).toHaveBeenCalledTimes(1); @@ -160,13 +160,13 @@ describe("applySafe in acompose tests", () => { expect(result).toBe(28); expect(catchFn).toHaveBeenCalledTimes(1); mockFnExpectations(catchFn, 1, 28, getError(input + 1)); - expect(catchInCatchBlockFn).not.toBeCalled(); - expect(increment2).not.toBeCalled(); - expect(increment3).not.toBeCalled(); + expect(catchInCatchBlockFn).not.toHaveBeenCalled(); + expect(increment2).not.toHaveBeenCalled(); + expect(increment3).not.toHaveBeenCalled(); expect(increment1).toHaveBeenCalledTimes(1); mockFnExpectations(increment1, 1, 8, input); }); - it("should work for case with reject in acompose chain", async () => { + it("should work for case with reject in acompose chain for first argument", async () => { expect.assertions(8); const input = 7; const increment1 = incrementMock(jest, "increment1"); @@ -181,10 +181,10 @@ describe("applySafe in acompose tests", () => { expect(result).toBe(28); expect(catchFn).toHaveBeenCalledTimes(1); mockFnExpectations(catchFn, 1, 28, getError(input)); - expect(catchInCatchBlockFn).not.toBeCalled(); - expect(increment1).not.toBeCalled(); - expect(increment2).not.toBeCalled(); - expect(increment3).not.toBeCalled(); + expect(catchInCatchBlockFn).not.toHaveBeenCalled(); + expect(increment1).not.toHaveBeenCalled(); + expect(increment2).not.toHaveBeenCalled(); + expect(increment3).not.toHaveBeenCalled(); }); it("should work for case with reject in input", async () => { expect.assertions(8); @@ -202,10 +202,10 @@ describe("applySafe in acompose tests", () => { expect(result).toBe(28); expect(catchFn).toHaveBeenCalledTimes(1); mockFnExpectations(catchFn, 1, 28, getError(input)); - expect(increment1).not.toBeCalled(); - expect(increment2).not.toBeCalled(); - expect(increment3).not.toBeCalled(); - expect(catchInCatchBlockFn).not.toBeCalled(); + expect(increment1).not.toHaveBeenCalled(); + expect(increment2).not.toHaveBeenCalled(); + expect(increment3).not.toHaveBeenCalled(); + expect(catchInCatchBlockFn).not.toHaveBeenCalled(); }); it("should work for case with reject in acompose chain and applySafe in middle", async () => { expect.assertions(10); @@ -222,11 +222,11 @@ describe("applySafe in acompose tests", () => { expect(result).toBe(29); expect(catchFn).toHaveBeenCalledTimes(1); mockFnExpectations(catchFn, 1, 28, getError(input)); - expect(catchInCatchBlockFn).not.toBeCalled(); - expect(increment1).not.toBeCalled(); + expect(catchInCatchBlockFn).not.toHaveBeenCalled(); + expect(increment1).not.toHaveBeenCalled(); expect(increment2).toHaveBeenCalledTimes(1); mockFnExpectations(increment2, 1, 29, 28); - expect(increment3).not.toBeCalled(); + expect(increment3).not.toHaveBeenCalled(); }); it("should work for case with rejection in applySafe", async () => { expect.assertions(12); @@ -241,12 +241,12 @@ describe("applySafe in acompose tests", () => { catchInCatchBlockFn ); expect(result).toBe(28); - expect(catchInCatchBlockFn).not.toBeCalled(); + expect(catchInCatchBlockFn).not.toHaveBeenCalled(); expect(increment1).toHaveBeenCalledTimes(1); mockFnExpectations(increment1, 1, 8, input); expect(increment2).toHaveBeenCalledTimes(1); mockFnExpectations(increment2, 1, 9, 8); - expect(increment3).not.toBeCalled(); + expect(increment3).not.toHaveBeenCalled(); expect(catchFn).toHaveBeenCalledTimes(1); mockFnExpectations(catchFn, 1, 28, getError(9)); }); @@ -264,8 +264,8 @@ describe("applySafe in apipe tests", () => { catchInCatchBlockFn ); expect(result).toBe(10); - expect(catchFn).not.toBeCalled(); - expect(catchInCatchBlockFn).not.toBeCalled(); + expect(catchFn).not.toHaveBeenCalled(); + expect(catchInCatchBlockFn).not.toHaveBeenCalled(); expect(increment1).toHaveBeenCalledTimes(1); mockFnExpectations(increment1, 1, 8, input); expect(increment2).toHaveBeenCalledTimes(1); @@ -288,13 +288,13 @@ describe("applySafe in apipe tests", () => { expect(result).toBe(28); expect(catchFn).toHaveBeenCalledTimes(1); mockFnExpectations(catchFn, 1, 28, getError(input + 1)); - expect(catchInCatchBlockFn).not.toBeCalled(); - expect(increment2).not.toBeCalled(); - expect(increment3).not.toBeCalled(); + expect(catchInCatchBlockFn).not.toHaveBeenCalled(); + expect(increment2).not.toHaveBeenCalled(); + expect(increment3).not.toHaveBeenCalled(); expect(increment1).toHaveBeenCalledTimes(1); mockFnExpectations(increment1, 1, 8, input); }); - it("should work for case with reject in apipe chain", async () => { + it("should work for case with reject in apipe chain for first argument", async () => { expect.assertions(8); const input = 7; const increment1 = incrementMock(jest, "increment1"); @@ -309,10 +309,10 @@ describe("applySafe in apipe tests", () => { expect(result).toBe(28); expect(catchFn).toHaveBeenCalledTimes(1); mockFnExpectations(catchFn, 1, 28, getError(input)); - expect(catchInCatchBlockFn).not.toBeCalled(); - expect(increment1).not.toBeCalled(); - expect(increment2).not.toBeCalled(); - expect(increment3).not.toBeCalled(); + expect(catchInCatchBlockFn).not.toHaveBeenCalled(); + expect(increment1).not.toHaveBeenCalled(); + expect(increment2).not.toHaveBeenCalled(); + expect(increment3).not.toHaveBeenCalled(); }); it("should work for case with reject in input", async () => { expect.assertions(8); @@ -330,10 +330,10 @@ describe("applySafe in apipe tests", () => { expect(result).toBe(28); expect(catchFn).toHaveBeenCalledTimes(1); mockFnExpectations(catchFn, 1, 28, getError(input)); - expect(increment1).not.toBeCalled(); - expect(increment2).not.toBeCalled(); - expect(increment3).not.toBeCalled(); - expect(catchInCatchBlockFn).not.toBeCalled(); + expect(increment1).not.toHaveBeenCalled(); + expect(increment2).not.toHaveBeenCalled(); + expect(increment3).not.toHaveBeenCalled(); + expect(catchInCatchBlockFn).not.toHaveBeenCalled(); }); it("should work for case with reject in apipe chain and applySafe in middle", async () => { expect.assertions(10); @@ -350,11 +350,11 @@ describe("applySafe in apipe tests", () => { expect(result).toBe(29); expect(catchFn).toHaveBeenCalledTimes(1); mockFnExpectations(catchFn, 1, 28, getError(input)); - expect(catchInCatchBlockFn).not.toBeCalled(); - expect(increment1).not.toBeCalled(); + expect(catchInCatchBlockFn).not.toHaveBeenCalled(); + expect(increment1).not.toHaveBeenCalled(); expect(increment2).toHaveBeenCalledTimes(1); mockFnExpectations(increment2, 1, 29, 28); - expect(increment3).not.toBeCalled(); + expect(increment3).not.toHaveBeenCalled(); }); it("should work for case with rejection in applySafe", async () => { expect.assertions(12); @@ -369,12 +369,12 @@ describe("applySafe in apipe tests", () => { catchInCatchBlockFn ); expect(result).toBe(28); - expect(catchInCatchBlockFn).not.toBeCalled(); + expect(catchInCatchBlockFn).not.toHaveBeenCalled(); expect(increment1).toHaveBeenCalledTimes(1); mockFnExpectations(increment1, 1, 8, input); expect(increment2).toHaveBeenCalledTimes(1); mockFnExpectations(increment2, 1, 9, 8); - expect(increment3).not.toBeCalled(); + expect(increment3).not.toHaveBeenCalled(); expect(catchFn).toHaveBeenCalledTimes(1); mockFnExpectations(catchFn, 1, 28, getError(9)); }); diff --git a/__tests__/areduce.js b/__tests__/areduce.js index 7956bba..4dc8396 100644 --- a/__tests__/areduce.js +++ b/__tests__/areduce.js @@ -13,84 +13,84 @@ describe("areduce tests", () => { it("should work for base case with synchronous data", async () => { expect.assertions(8); const sumFn = sumReduceFnMock(jest, "sumFn"); - const arg1 = 1; - const arg2 = 2; - const arg3 = 3; - const arg4 = 2; - const input = [arg1, arg2, arg3, arg4]; + const argument1 = 1; + const argument2 = 2; + const argument3 = 3; + const argument4 = 2; + const input = [argument1, argument2, argument3, argument4]; const sum = await areduce(sumFn)(input); const expectedResult = 8; expect(sumFn).toHaveBeenCalledTimes(3); - mockFnExpectations(sumFn, 1, 3, arg1, arg2, 1, input); - mockFnExpectations(sumFn, 2, 6, 3, arg3, 2, input); - mockFnExpectations(sumFn, 3, expectedResult, 6, arg4, 3, input); + mockFnExpectations(sumFn, 1, 3, argument1, argument2, 1, input); + mockFnExpectations(sumFn, 2, 6, 3, argument3, 2, input); + mockFnExpectations(sumFn, 3, expectedResult, 6, argument4, 3, input); expect(sum).toBe(expectedResult); }); it("should work for base case with synchronous data and with non symmetrical operation", async () => { expect.assertions(8); const deductionFn = deductionReduceFnMock(jest, "sumFn"); - const arg1 = 10; - const arg2 = 2; - const arg3 = 3; - const arg4 = 2; - const input = [arg1, arg2, arg3, arg4]; + const argument1 = 10; + const argument2 = 2; + const argument3 = 3; + const argument4 = 2; + const input = [argument1, argument2, argument3, argument4]; const sum = await areduce(deductionFn)(input); const expectedResult = 3; expect(deductionFn).toHaveBeenCalledTimes(3); - mockFnExpectations(deductionFn, 1, 8, arg1, arg2, 1, input); - mockFnExpectations(deductionFn, 2, 5, 8, arg3, 2, input); - mockFnExpectations(deductionFn, 3, expectedResult, 5, arg4, 3, input); + mockFnExpectations(deductionFn, 1, 8, argument1, argument2, 1, input); + mockFnExpectations(deductionFn, 2, 5, 8, argument3, 2, input); + mockFnExpectations(deductionFn, 3, expectedResult, 5, argument4, 3, input); expect(sum).toBe(expectedResult); }); it("should work for base case with synchronous data and initial value", async () => { expect.assertions(8); const sumFn = sumReduceFnMock(jest, "sumFn"); - const arg1 = 1; - const arg2 = 2; - const arg3 = 3; + const argument1 = 1; + const argument2 = 2; + const argument3 = 3; const initialAcc = 7; - const input = [arg1, arg2, arg3]; + const input = [argument1, argument2, argument3]; const sum = await areduce(sumFn, initialAcc)(new Set(input)); const expectedResult = 13; expect(sumFn).toHaveBeenCalledTimes(3); - mockFnExpectations(sumFn, 1, 8, initialAcc, arg1, 0, input); - mockFnExpectations(sumFn, 2, 10, 8, arg2, 1, input); - mockFnExpectations(sumFn, 3, expectedResult, 10, arg3, 2, input); + mockFnExpectations(sumFn, 1, 8, initialAcc, argument1, 0, input); + mockFnExpectations(sumFn, 2, 10, 8, argument2, 1, input); + mockFnExpectations(sumFn, 3, expectedResult, 10, argument3, 2, input); expect(sum).toBe(expectedResult); }); it("should work for base case with synchronous data and initial value and with non symmetrical operation", async () => { expect.assertions(8); const concatenationFn = concatenationReduceFnMock(jest, "sumFn"); - const arg1 = 1; - const arg2 = 2; - const arg3 = 3; + const argument1 = 1; + const argument2 = 2; + const argument3 = 3; const initialAcc = 10; - const input = [arg1, arg2, arg3]; + const input = [argument1, argument2, argument3]; const result = await areduce(concatenationFn, initialAcc)(new Set(input)); const expectedResult = "10123"; expect(concatenationFn).toHaveBeenCalledTimes(3); - mockFnExpectations(concatenationFn, 1, "101", initialAcc, arg1, 0, input); - mockFnExpectations(concatenationFn, 2, "1012", "101", arg2, 1, input); - mockFnExpectations(concatenationFn, 3, expectedResult, "1012", arg3, 2, input); + mockFnExpectations(concatenationFn, 1, "101", initialAcc, argument1, 0, input); + mockFnExpectations(concatenationFn, 2, "1012", "101", argument2, 1, input); + mockFnExpectations(concatenationFn, 3, expectedResult, "1012", argument3, 2, input); expect(result).toBe(expectedResult); }); it("should work for promise as input and with non symmetrical operation and initial value", async () => { expect.assertions(11); const concatenationFn = concatenationReduceFnMock(jest, "sumFn"); - const arg1 = 1; - const arg2 = 2; - const arg3 = 3; + const argument1 = 1; + const argument2 = 2; + const argument3 = 3; const initialAcc = 10; const identity = identityMock(jest, "identity"); - const inputValue = [arg1, arg2, arg3]; + const inputValue = [argument1, argument2, argument3]; const input = new Set(inputValue); const result = await areduce(concatenationFn, initialAcc)(createAsyncPromise(identity)(input)); @@ -100,19 +100,19 @@ describe("areduce tests", () => { mockFnExpectations(identity, 1, input, input); expect(identity).toHaveBeenCalledTimes(1); expect(concatenationFn).toHaveBeenCalledTimes(3); - mockFnExpectations(concatenationFn, 1, "101", initialAcc, arg1, 0, inputValue); - mockFnExpectations(concatenationFn, 2, "1012", "101", arg2, 1, inputValue); - mockFnExpectations(concatenationFn, 3, expectedResult, "1012", arg3, 2, inputValue); + mockFnExpectations(concatenationFn, 1, "101", initialAcc, argument1, 0, inputValue); + mockFnExpectations(concatenationFn, 2, "1012", "101", argument2, 1, inputValue); + mockFnExpectations(concatenationFn, 3, expectedResult, "1012", argument3, 2, inputValue); }); it("should work for promise as input and with non symmetrical operation and without initial value", async () => { expect.assertions(11); const concatenationFn = concatenationReduceFnMock(jest, "sumFn"); - const arg1 = 10; - const arg2 = 2; - const arg3 = 3; - const arg4 = 2; + const argument1 = 10; + const argument2 = 2; + const argument3 = 3; + const argument4 = 2; const identity = identityMock(jest, "identity"); - const input = [arg1, arg2, arg3, arg4]; + const input = [argument1, argument2, argument3, argument4]; const result = await areduce(concatenationFn)(createAsyncPromise(identity)(input)); @@ -121,9 +121,9 @@ describe("areduce tests", () => { mockFnExpectations(identity, 1, input, input); expect(identity).toHaveBeenCalledTimes(1); expect(concatenationFn).toHaveBeenCalledTimes(3); - mockFnExpectations(concatenationFn, 1, "102", arg1, arg2, 1, input); - mockFnExpectations(concatenationFn, 2, "1023", "102", arg3, 2, input); - mockFnExpectations(concatenationFn, 3, expectedResult, "1023", arg4, 3, input); + mockFnExpectations(concatenationFn, 1, "102", argument1, argument2, 1, input); + mockFnExpectations(concatenationFn, 2, "1023", "102", argument3, 2, input); + mockFnExpectations(concatenationFn, 3, expectedResult, "1023", argument4, 3, input); }); it("should work with promise as input", async () => { expect.assertions(4); @@ -146,55 +146,55 @@ describe("areduce tests", () => { } catch (e) { expect(e).toBeInstanceOf(Error); expect(e.message).toBe(getErrorMessage(input)); - expect(identity).not.toBeCalled(); + expect(identity).not.toHaveBeenCalled(); } }); it("should work for mixed list of promises and not as input and with non symmetrical operation and promised initial value", async () => { expect.assertions(17); const concatenationFn = concatenationReduceFnMock(jest, "sumFn"); - const identityArg1 = identityMock(jest, "identityArg1"); - const identityArg3 = identityMock(jest, "identityArg3"); + const identityArgument1 = identityMock(jest, "identityArgument1"); + const identityArgument3 = identityMock(jest, "identityArgument3"); const identityAcc = identityMock(jest, "identityAcc"); - const arg1Value = 1; - const arg1 = createAsyncPromise(identityArg1)(arg1Value); - const arg2 = 2; - const arg3Value = 3; - const arg3 = createSyncPromise(identityArg3)(arg3Value); + const argument1Value = 1; + const argument1 = createAsyncPromise(identityArgument1)(argument1Value); + const argument2 = 2; + const argument3Value = 3; + const argument3 = createSyncPromise(identityArgument3)(argument3Value); const initialAccValue = 10; const initialAcc = createAsyncPromise(identityAcc)(initialAccValue); - const inputValue = [arg1, arg2, arg3]; - const inputValueResolved = [arg1Value, arg2, arg3Value]; + const inputValue = [argument1, argument2, argument3]; + const inputValueResolved = [argument1Value, argument2, argument3Value]; const input = new Set(inputValue); const result = await areduce(concatenationFn, initialAcc)(input); const expectedResult = "10123"; expect(result).toBe(expectedResult); - mockFnExpectations(identityArg1, 1, arg1Value, arg1Value); - expect(identityArg1).toHaveBeenCalledTimes(1); - mockFnExpectations(identityArg3, 1, arg3Value, arg3Value); - expect(identityArg3).toHaveBeenCalledTimes(1); + mockFnExpectations(identityArgument1, 1, argument1Value, argument1Value); + expect(identityArgument1).toHaveBeenCalledTimes(1); + mockFnExpectations(identityArgument3, 1, argument3Value, argument3Value); + expect(identityArgument3).toHaveBeenCalledTimes(1); mockFnExpectations(identityAcc, 1, initialAccValue, initialAccValue); expect(identityAcc).toHaveBeenCalledTimes(1); expect(concatenationFn).toHaveBeenCalledTimes(3); - mockFnExpectations(concatenationFn, 1, "101", initialAccValue, arg1Value, 0, inputValueResolved); - mockFnExpectations(concatenationFn, 2, "1012", "101", arg2, 1, inputValueResolved); - mockFnExpectations(concatenationFn, 3, expectedResult, "1012", arg3Value, 2, inputValueResolved); + mockFnExpectations(concatenationFn, 1, "101", initialAccValue, argument1Value, 0, inputValueResolved); + mockFnExpectations(concatenationFn, 2, "1012", "101", argument2, 1, inputValueResolved); + mockFnExpectations(concatenationFn, 3, expectedResult, "1012", argument3Value, 2, inputValueResolved); }); it("should reject for mixed list of promises and not as input and with non symmetrical operation and promised initial value and fail in first input", async () => { expect.assertions(7); const concatenationFn = concatenationReduceFnMock(jest, "sumFn"); - const identityArg1 = identityMock(jest, "identityArg1"); - const identityArg3 = identityMock(jest, "identityArg3"); + const identityArgument1 = identityMock(jest, "identityArgument1"); + const identityArgument3 = identityMock(jest, "identityArgument3"); const identityAcc = identityMock(jest, "identityAcc"); - const arg1Value = 1; - const arg1 = createAsyncPromise(identityArg1, false)(arg1Value); - const arg2 = 2; - const arg3Value = 3; - const arg3 = createSyncPromise(identityArg3)(arg3Value); + const argument1Value = 1; + const argument1 = createAsyncPromise(identityArgument1, false)(argument1Value); + const argument2 = 2; + const argument3Value = 3; + const argument3 = createSyncPromise(identityArgument3)(argument3Value); const initialAccValue = 10; const initialAcc = createAsyncPromise(identityAcc)(initialAccValue); - const inputValue = [arg1, arg2, arg3]; + const inputValue = [argument1, argument2, argument3]; const input = new Set(inputValue); try { @@ -202,126 +202,126 @@ describe("areduce tests", () => { expect(false).toBe(true); } catch (e) { expect(e).toBeInstanceOf(Error); - expect(e.message).toBe(getErrorMessage(arg1Value)); + expect(e.message).toBe(getErrorMessage(argument1Value)); mockFnExpectations(identityAcc, 1, initialAccValue, initialAccValue); expect(identityAcc).toHaveBeenCalledTimes(1); - expect(identityArg1).not.toBeCalled(); - expect(concatenationFn).not.toBeCalled(); + expect(identityArgument1).not.toHaveBeenCalled(); + expect(concatenationFn).not.toHaveBeenCalled(); } }); it("should reject for mixed list of promises and not as input and with non symmetrical operation and promised initial value and fail in last input", async () => { expect.assertions(10); const concatenationFn = concatenationReduceFnMock(jest, "sumFn"); - const identityArg1 = identityMock(jest, "identityArg1"); - const identityArg3 = identityMock(jest, "identityArg3"); + const identityArgument1 = identityMock(jest, "identityArgument1"); + const identityArgument3 = identityMock(jest, "identityArgument3"); const identityAcc = identityMock(jest, "identityAcc"); - const arg1Value = 1; - const arg1 = createAsyncPromise(identityArg1)(arg1Value); - const arg2 = 2; - const arg3Value = 3; - const arg3 = createAsyncPromise(identityArg3, false)(arg3Value); + const argument1Value = 1; + const argument1 = createAsyncPromise(identityArgument1)(argument1Value); + const argument2 = 2; + const argument3Value = 3; + const argument3 = createAsyncPromise(identityArgument3, false)(argument3Value); const initialAccValue = 10; const initialAcc = createAsyncPromise(identityAcc)(initialAccValue); - const input = new Set([arg1, arg2, arg3]); + const input = new Set([argument1, argument2, argument3]); try { await areduce(concatenationFn, initialAcc)(input); expect(false).toBe(true); } catch (e) { expect(e).toBeInstanceOf(Error); - expect(e.message).toBe(getErrorMessage(arg3Value)); - mockFnExpectations(identityArg1, 1, arg1Value, arg1Value); - expect(identityArg1).toHaveBeenCalledTimes(1); + expect(e.message).toBe(getErrorMessage(argument3Value)); + mockFnExpectations(identityArgument1, 1, argument1Value, argument1Value); + expect(identityArgument1).toHaveBeenCalledTimes(1); mockFnExpectations(identityAcc, 1, initialAccValue, initialAccValue); expect(identityAcc).toHaveBeenCalledTimes(1); - expect(concatenationFn).not.toBeCalled(); - expect(identityArg3).not.toBeCalled(); + expect(concatenationFn).not.toHaveBeenCalled(); + expect(identityArgument3).not.toHaveBeenCalled(); } }); it("should work for mixed list of promises and not as input and with non symmetrical operation and promised initial value with promise in reduce function", async () => { expect.assertions(17); const concatenationFn = concatenationReduceFnMock(jest, "sumFn"); const asyncConcatenationFn = createAsyncPromise(concatenationFn); - const identityArg1 = identityMock(jest, "identityArg1"); - const identityArg3 = identityMock(jest, "identityArg3"); + const identityArgument1 = identityMock(jest, "identityArgument1"); + const identityArgument3 = identityMock(jest, "identityArgument3"); const identityAcc = identityMock(jest, "identityAcc"); - const arg1Value = 1; - const arg1 = createAsyncPromise(identityArg1)(arg1Value); - const arg2 = 2; - const arg3Value = 3; - const arg3 = createSyncPromise(identityArg3)(arg3Value); + const argument1Value = 1; + const argument1 = createAsyncPromise(identityArgument1)(argument1Value); + const argument2 = 2; + const argument3Value = 3; + const argument3 = createSyncPromise(identityArgument3)(argument3Value); const initialAccValue = 10; const initialAcc = createAsyncPromise(identityAcc)(initialAccValue); - const inputValue = [arg1, arg2, arg3]; + const inputValue = [argument1, argument2, argument3]; const input = new Set(inputValue); - const inputValueResolved = [arg1Value, arg2, arg3Value]; + const inputValueResolved = [argument1Value, argument2, argument3Value]; const result = await areduce(asyncConcatenationFn, initialAcc)(input); const expectedResult = "10123"; expect(result).toBe(expectedResult); - mockFnExpectations(identityArg1, 1, arg1Value, arg1Value); - expect(identityArg1).toHaveBeenCalledTimes(1); - mockFnExpectations(identityArg3, 1, arg3Value, arg3Value); - expect(identityArg3).toHaveBeenCalledTimes(1); + mockFnExpectations(identityArgument1, 1, argument1Value, argument1Value); + expect(identityArgument1).toHaveBeenCalledTimes(1); + mockFnExpectations(identityArgument3, 1, argument3Value, argument3Value); + expect(identityArgument3).toHaveBeenCalledTimes(1); mockFnExpectations(identityAcc, 1, initialAccValue, initialAccValue); expect(identityAcc).toHaveBeenCalledTimes(1); expect(concatenationFn).toHaveBeenCalledTimes(3); - mockFnExpectations(concatenationFn, 1, "101", initialAccValue, arg1Value, 0, inputValueResolved); - mockFnExpectations(concatenationFn, 2, "1012", "101", arg2, 1, inputValueResolved); - mockFnExpectations(concatenationFn, 3, expectedResult, "1012", arg3Value, 2, inputValueResolved); + mockFnExpectations(concatenationFn, 1, "101", initialAccValue, argument1Value, 0, inputValueResolved); + mockFnExpectations(concatenationFn, 2, "1012", "101", argument2, 1, inputValueResolved); + mockFnExpectations(concatenationFn, 3, expectedResult, "1012", argument3Value, 2, inputValueResolved); }); it("should work for mixed list of promises and not as input and with non symmetrical operation", async () => { expect.assertions(12); const concatenationFn = concatenationReduceFnMock(jest, "sumFn"); - const identityArg1 = identityMock(jest, "identityArg1"); - const identityArg3 = identityMock(jest, "identityArg3"); - const arg1Value = 1; - const arg1 = createAsyncPromise(identityArg1)(arg1Value); - const arg2 = 2; - const arg3Value = 3; - const arg3 = createSyncPromise(identityArg3)(arg3Value); - const inputValue = [arg1, arg2, arg3]; + const identityArgument1 = identityMock(jest, "identityArgument1"); + const identityArgument3 = identityMock(jest, "identityArgument3"); + const argument1Value = 1; + const argument1 = createAsyncPromise(identityArgument1)(argument1Value); + const argument2 = 2; + const argument3Value = 3; + const argument3 = createSyncPromise(identityArgument3)(argument3Value); + const inputValue = [argument1, argument2, argument3]; const input = new Set(inputValue); - const inputValueResolved = [arg1Value, arg2, arg3Value]; + const inputValueResolved = [argument1Value, argument2, argument3Value]; const result = await areduce(concatenationFn)(input); const expectedResult = "123"; expect(result).toBe(expectedResult); - mockFnExpectations(identityArg1, 1, arg1Value, arg1Value); - expect(identityArg1).toHaveBeenCalledTimes(1); - mockFnExpectations(identityArg3, 1, arg3Value, arg3Value); - expect(identityArg3).toHaveBeenCalledTimes(1); + mockFnExpectations(identityArgument1, 1, argument1Value, argument1Value); + expect(identityArgument1).toHaveBeenCalledTimes(1); + mockFnExpectations(identityArgument3, 1, argument3Value, argument3Value); + expect(identityArgument3).toHaveBeenCalledTimes(1); expect(concatenationFn).toHaveBeenCalledTimes(2); - mockFnExpectations(concatenationFn, 1, "12", arg1Value, arg2, 1, inputValueResolved); - mockFnExpectations(concatenationFn, 2, expectedResult, "12", arg3Value, 2, inputValueResolved); + mockFnExpectations(concatenationFn, 1, "12", argument1Value, argument2, 1, inputValueResolved); + mockFnExpectations(concatenationFn, 2, expectedResult, "12", argument3Value, 2, inputValueResolved); }); it("should work for mixed list of promises and not as input and with non symmetrical operation with promise in reduce function", async () => { expect.assertions(12); const concatenationFn = concatenationReduceFnMock(jest, "sumFn"); const asyncConcatenationFn = createAsyncPromise(concatenationFn); - const identityArg1 = identityMock(jest, "identityArg1"); - const identityArg3 = identityMock(jest, "identityArg3"); - const arg1Value = 1; - const arg1 = createAsyncPromise(identityArg1)(arg1Value); - const arg2 = 2; - const arg3Value = 3; - const arg3 = createSyncPromise(identityArg3)(arg3Value); - const inputValue = [arg1, arg2, arg3]; + const identityArgument1 = identityMock(jest, "identityArgument1"); + const identityArgument3 = identityMock(jest, "identityArgument3"); + const argument1Value = 1; + const argument1 = createAsyncPromise(identityArgument1)(argument1Value); + const argument2 = 2; + const argument3Value = 3; + const argument3 = createSyncPromise(identityArgument3)(argument3Value); + const inputValue = [argument1, argument2, argument3]; const input = new Set(inputValue); - const inputValueResolved = [arg1Value, arg2, arg3Value]; + const inputValueResolved = [argument1Value, argument2, argument3Value]; const result = await areduce(asyncConcatenationFn)(input); const expectedResult = "123"; expect(result).toBe(expectedResult); - mockFnExpectations(identityArg1, 1, arg1Value, arg1Value); - expect(identityArg1).toHaveBeenCalledTimes(1); - mockFnExpectations(identityArg3, 1, arg3Value, arg3Value); - expect(identityArg3).toHaveBeenCalledTimes(1); + mockFnExpectations(identityArgument1, 1, argument1Value, argument1Value); + expect(identityArgument1).toHaveBeenCalledTimes(1); + mockFnExpectations(identityArgument3, 1, argument3Value, argument3Value); + expect(identityArgument3).toHaveBeenCalledTimes(1); expect(concatenationFn).toHaveBeenCalledTimes(2); - mockFnExpectations(concatenationFn, 1, "12", arg1Value, arg2, 1, inputValueResolved); - mockFnExpectations(concatenationFn, 2, expectedResult, "12", arg3Value, 2, inputValueResolved); + mockFnExpectations(concatenationFn, 1, "12", argument1Value, argument2, 1, inputValueResolved); + mockFnExpectations(concatenationFn, 2, expectedResult, "12", argument3Value, 2, inputValueResolved); }); }); diff --git a/__tests__/areduceRight.js b/__tests__/areduceRight.js index 027c30c..43cb6e7 100644 --- a/__tests__/areduceRight.js +++ b/__tests__/areduceRight.js @@ -13,84 +13,84 @@ describe("areduceRight tests", () => { it("should work for base case with synchronous data", async () => { expect.assertions(8); const sumFn = sumReduceFnMock(jest, "sumFn"); - const arg1 = 2; - const arg2 = 3; - const arg3 = 2; - const arg4 = 1; + const argument1 = 2; + const argument2 = 3; + const argument3 = 2; + const argument4 = 1; - const inputValue = [arg1, arg2, arg3, arg4]; + const inputValue = [argument1, argument2, argument3, argument4]; const sum = await areduceRight(sumFn)(inputValue); const expectedResult = 8; expect(sumFn).toHaveBeenCalledTimes(3); - mockFnExpectations(sumFn, 1, 3, arg4, arg3, 2, inputValue); - mockFnExpectations(sumFn, 2, 6, 3, arg2, 1, inputValue); - mockFnExpectations(sumFn, 3, expectedResult, 6, arg1, 0, inputValue); + mockFnExpectations(sumFn, 1, 3, argument4, argument3, 2, inputValue); + mockFnExpectations(sumFn, 2, 6, 3, argument2, 1, inputValue); + mockFnExpectations(sumFn, 3, expectedResult, 6, argument1, 0, inputValue); expect(sum).toBe(expectedResult); }); it("should work for base case with synchronous data and with non symmetrical operation", async () => { expect.assertions(8); const deductionFn = deductionReduceFnMock(jest, "deductionFn"); - const arg1 = 2; - const arg2 = 3; - const arg3 = 2; - const arg4 = 10; + const argument1 = 2; + const argument2 = 3; + const argument3 = 2; + const argument4 = 10; - const inputValue = [arg1, arg2, arg3, arg4]; + const inputValue = [argument1, argument2, argument3, argument4]; const sum = await areduceRight(deductionFn)(inputValue); const expectedResult = 3; expect(deductionFn).toHaveBeenCalledTimes(3); - mockFnExpectations(deductionFn, 1, 8, arg4, arg3, 2, inputValue); - mockFnExpectations(deductionFn, 2, 5, 8, arg2, 1, inputValue); - mockFnExpectations(deductionFn, 3, expectedResult, 5, arg1, 0, inputValue); + mockFnExpectations(deductionFn, 1, 8, argument4, argument3, 2, inputValue); + mockFnExpectations(deductionFn, 2, 5, 8, argument2, 1, inputValue); + mockFnExpectations(deductionFn, 3, expectedResult, 5, argument1, 0, inputValue); expect(sum).toBe(expectedResult); }); it("should work for base case with synchronous data and initial value", async () => { expect.assertions(8); const sumFn = sumReduceFnMock(jest, "sumFn"); - const arg1 = 3; - const arg2 = 2; - const arg3 = 1; + const argument1 = 3; + const argument2 = 2; + const argument3 = 1; const initialAcc = 7; - const inputValue = [arg1, arg2, arg3]; + const inputValue = [argument1, argument2, argument3]; const sum = await areduceRight(sumFn, initialAcc)(new Set(inputValue)); const expectedResult = 13; expect(sumFn).toHaveBeenCalledTimes(3); - mockFnExpectations(sumFn, 1, 8, initialAcc, arg3, 2, inputValue); - mockFnExpectations(sumFn, 2, 10, 8, arg2, 1, inputValue); - mockFnExpectations(sumFn, 3, expectedResult, 10, arg1, 0, inputValue); + mockFnExpectations(sumFn, 1, 8, initialAcc, argument3, 2, inputValue); + mockFnExpectations(sumFn, 2, 10, 8, argument2, 1, inputValue); + mockFnExpectations(sumFn, 3, expectedResult, 10, argument1, 0, inputValue); expect(sum).toBe(expectedResult); }); it("should work for base case with synchronous data and initial value and with non symmetrical operation", async () => { expect.assertions(8); const concatenationFn = concatenationReduceFnMock(jest, "sumFn"); - const arg1 = 3; - const arg2 = 2; - const arg3 = 1; + const argument1 = 3; + const argument2 = 2; + const argument3 = 1; const initialAcc = 10; - const inputValue = [arg1, arg2, arg3]; + const inputValue = [argument1, argument2, argument3]; const result = await areduceRight(concatenationFn, initialAcc)(new Set(inputValue)); const expectedResult = "10123"; expect(concatenationFn).toHaveBeenCalledTimes(3); - mockFnExpectations(concatenationFn, 1, "101", initialAcc, arg3, 2, inputValue); - mockFnExpectations(concatenationFn, 2, "1012", "101", arg2, 1, inputValue); - mockFnExpectations(concatenationFn, 3, expectedResult, "1012", arg1, 0, inputValue); + mockFnExpectations(concatenationFn, 1, "101", initialAcc, argument3, 2, inputValue); + mockFnExpectations(concatenationFn, 2, "1012", "101", argument2, 1, inputValue); + mockFnExpectations(concatenationFn, 3, expectedResult, "1012", argument1, 0, inputValue); expect(result).toBe(expectedResult); }); it("should work for promise as input and with non symmetrical operation and initial value", async () => { expect.assertions(11); const concatenationFn = concatenationReduceFnMock(jest, "sumFn"); - const arg1 = 3; - const arg2 = 2; - const arg3 = 1; + const argument1 = 3; + const argument2 = 2; + const argument3 = 1; const initialAcc = 10; const identity = identityMock(jest, "identity"); - const inputValue = [arg1, arg2, arg3]; + const inputValue = [argument1, argument2, argument3]; const input = new Set(inputValue); const result = await areduceRight(concatenationFn, initialAcc)(createAsyncPromise(identity)(input)); @@ -100,19 +100,19 @@ describe("areduceRight tests", () => { mockFnExpectations(identity, 1, input, input); expect(identity).toHaveBeenCalledTimes(1); expect(concatenationFn).toHaveBeenCalledTimes(3); - mockFnExpectations(concatenationFn, 1, "101", initialAcc, arg3, 2, inputValue); - mockFnExpectations(concatenationFn, 2, "1012", "101", arg2, 1, inputValue); - mockFnExpectations(concatenationFn, 3, expectedResult, "1012", arg1, 0, inputValue); + mockFnExpectations(concatenationFn, 1, "101", initialAcc, argument3, 2, inputValue); + mockFnExpectations(concatenationFn, 2, "1012", "101", argument2, 1, inputValue); + mockFnExpectations(concatenationFn, 3, expectedResult, "1012", argument1, 0, inputValue); }); it("should work for promise as input and with non symmetrical operation and without initial value", async () => { expect.assertions(11); const concatenationFn = concatenationReduceFnMock(jest, "sumFn"); - const arg1 = 2; - const arg2 = 3; - const arg3 = 2; - const arg4 = 10; + const argument1 = 2; + const argument2 = 3; + const argument3 = 2; + const argument4 = 10; const identity = identityMock(jest, "identity"); - const inputValue = [arg1, arg2, arg3, arg4]; + const inputValue = [argument1, argument2, argument3, argument4]; const result = await areduceRight(concatenationFn)(createAsyncPromise(identity)(inputValue)); @@ -121,9 +121,9 @@ describe("areduceRight tests", () => { mockFnExpectations(identity, 1, inputValue, inputValue); expect(identity).toHaveBeenCalledTimes(1); expect(concatenationFn).toHaveBeenCalledTimes(3); - mockFnExpectations(concatenationFn, 1, "102", arg4, arg3, 2, inputValue); - mockFnExpectations(concatenationFn, 2, "1023", "102", arg2, 1, inputValue); - mockFnExpectations(concatenationFn, 3, expectedResult, "1023", arg1, 0, inputValue); + mockFnExpectations(concatenationFn, 1, "102", argument4, argument3, 2, inputValue); + mockFnExpectations(concatenationFn, 2, "1023", "102", argument2, 1, inputValue); + mockFnExpectations(concatenationFn, 3, expectedResult, "1023", argument1, 0, inputValue); }); it("should work with promise as input", async () => { expect.assertions(4); @@ -146,181 +146,181 @@ describe("areduceRight tests", () => { } catch (e) { expect(e).toBeInstanceOf(Error); expect(e.message).toBe(getErrorMessage(input)); - expect(identity).not.toBeCalled(); + expect(identity).not.toHaveBeenCalled(); } }); it("should work for mixed list of promises and not as input and with non symmetrical operation and promised initial value", async () => { expect.assertions(17); const concatenationFn = concatenationReduceFnMock(jest, "sumFn"); - const identityArg1 = identityMock(jest, "identityArg1"); - const identityArg3 = identityMock(jest, "identityArg3"); + const identityArgument1 = identityMock(jest, "identityArgument1"); + const identityArgument3 = identityMock(jest, "identityArgument3"); const identityAcc = identityMock(jest, "identityAcc"); - const arg1Value = 3; - const arg1 = createSyncPromise(identityArg1)(arg1Value); - const arg2 = 2; - const arg3Value = 1; - const arg3 = createAsyncPromise(identityArg3)(arg3Value); + const argument1Value = 3; + const argument1 = createSyncPromise(identityArgument1)(argument1Value); + const argument2 = 2; + const argument3Value = 1; + const argument3 = createAsyncPromise(identityArgument3)(argument3Value); const initialAccValue = 10; const initialAcc = createAsyncPromise(identityAcc)(initialAccValue); - const inputValue = [arg1, arg2, arg3]; + const inputValue = [argument1, argument2, argument3]; const input = new Set(inputValue); - const inputValueResolved = [arg1Value, arg2, arg3Value]; + const inputValueResolved = [argument1Value, argument2, argument3Value]; const result = await areduceRight(concatenationFn, initialAcc)(input); const expectedResult = "10123"; expect(result).toBe(expectedResult); - mockFnExpectations(identityArg3, 1, arg3Value, arg3Value); - expect(identityArg3).toHaveBeenCalledTimes(1); - mockFnExpectations(identityArg1, 1, arg1Value, arg1Value); - expect(identityArg1).toHaveBeenCalledTimes(1); + mockFnExpectations(identityArgument3, 1, argument3Value, argument3Value); + expect(identityArgument3).toHaveBeenCalledTimes(1); + mockFnExpectations(identityArgument1, 1, argument1Value, argument1Value); + expect(identityArgument1).toHaveBeenCalledTimes(1); mockFnExpectations(identityAcc, 1, initialAccValue, initialAccValue); expect(identityAcc).toHaveBeenCalledTimes(1); expect(concatenationFn).toHaveBeenCalledTimes(3); - mockFnExpectations(concatenationFn, 1, "101", initialAccValue, arg3Value, 2, inputValueResolved); - mockFnExpectations(concatenationFn, 2, "1012", "101", arg2, 1, inputValueResolved); - mockFnExpectations(concatenationFn, 3, expectedResult, "1012", arg1Value, 0, inputValueResolved); + mockFnExpectations(concatenationFn, 1, "101", initialAccValue, argument3Value, 2, inputValueResolved); + mockFnExpectations(concatenationFn, 2, "1012", "101", argument2, 1, inputValueResolved); + mockFnExpectations(concatenationFn, 3, expectedResult, "1012", argument1Value, 0, inputValueResolved); }); it("should reject for mixed list of promises and not as input and with non symmetrical operation and promised initial value and fail in first input", async () => { expect.assertions(7); const concatenationFn = concatenationReduceFnMock(jest, "sumFn"); - const identityArg1 = identityMock(jest, "identityArg1"); - const identityArg3 = identityMock(jest, "identityArg3"); + const identityArgument1 = identityMock(jest, "identityArgument1"); + const identityArgument3 = identityMock(jest, "identityArgument3"); const identityAcc = identityMock(jest, "identityAcc"); - const arg1Value = 3; - const arg1 = createSyncPromise(identityArg1)(arg1Value); - const arg2 = 2; - const arg3Value = 1; - const arg3 = createAsyncPromise(identityArg3, false)(arg3Value); + const argument1Value = 3; + const argument1 = createSyncPromise(identityArgument1)(argument1Value); + const argument2 = 2; + const argument3Value = 1; + const argument3 = createAsyncPromise(identityArgument3, false)(argument3Value); const initialAccValue = 10; const initialAcc = createAsyncPromise(identityAcc)(initialAccValue); - const input = new Set([arg1, arg2, arg3]); + const input = new Set([argument1, argument2, argument3]); try { await areduceRight(concatenationFn, initialAcc)(input); expect(false).toBe(true); } catch (e) { expect(e).toBeInstanceOf(Error); - expect(e.message).toBe(getErrorMessage(arg3Value)); + expect(e.message).toBe(getErrorMessage(argument3Value)); mockFnExpectations(identityAcc, 1, initialAccValue, initialAccValue); expect(identityAcc).toHaveBeenCalledTimes(1); - expect(identityArg3).not.toBeCalled(); - expect(concatenationFn).not.toBeCalled(); + expect(identityArgument3).not.toHaveBeenCalled(); + expect(concatenationFn).not.toHaveBeenCalled(); } }); it("should reject for mixed list of promises and not as input and with non symmetrical operation and promised initial value and fail in last input", async () => { expect.assertions(10); const concatenationFn = concatenationReduceFnMock(jest, "sumFn"); - const identityArg1 = identityMock(jest, "identityArg1"); - const identityArg3 = identityMock(jest, "identityArg3"); + const identityArgument1 = identityMock(jest, "identityArgument1"); + const identityArgument3 = identityMock(jest, "identityArgument3"); const identityAcc = identityMock(jest, "identityAcc"); - const arg1Value = 3; - const arg1 = createAsyncPromise(identityArg1, false)(arg1Value); - const arg2 = 2; - const arg3Value = 1; - const arg3 = createAsyncPromise(identityArg3)(arg3Value); + const argument1Value = 3; + const argument1 = createAsyncPromise(identityArgument1, false)(argument1Value); + const argument2 = 2; + const argument3Value = 1; + const argument3 = createAsyncPromise(identityArgument3)(argument3Value); const initialAccValue = 10; const initialAcc = createAsyncPromise(identityAcc)(initialAccValue); - const input = new Set([arg1, arg2, arg3]); + const input = new Set([argument1, argument2, argument3]); try { await areduceRight(concatenationFn, initialAcc)(input); expect(false).toBe(true); } catch (e) { expect(e).toBeInstanceOf(Error); - expect(e.message).toBe(getErrorMessage(arg1Value)); - mockFnExpectations(identityArg3, 1, arg3Value, arg3Value); - expect(identityArg3).toHaveBeenCalledTimes(1); + expect(e.message).toBe(getErrorMessage(argument1Value)); + mockFnExpectations(identityArgument3, 1, argument3Value, argument3Value); + expect(identityArgument3).toHaveBeenCalledTimes(1); mockFnExpectations(identityAcc, 1, initialAccValue, initialAccValue); expect(identityAcc).toHaveBeenCalledTimes(1); - expect(concatenationFn).not.toBeCalled(); - expect(identityArg1).not.toBeCalled(); + expect(concatenationFn).not.toHaveBeenCalled(); + expect(identityArgument1).not.toHaveBeenCalled(); } }); it("should work for mixed list of promises and not as input and with non symmetrical operation and promised initial value with promise in reduce function", async () => { expect.assertions(17); const concatenationFn = concatenationReduceFnMock(jest, "sumFn"); const asyncConcatenationFn = createAsyncPromise(concatenationFn); - const identityArg1 = identityMock(jest, "identityArg1"); - const identityArg3 = identityMock(jest, "identityArg3"); + const identityArgument1 = identityMock(jest, "identityArgument1"); + const identityArgument3 = identityMock(jest, "identityArgument3"); const identityAcc = identityMock(jest, "identityAcc"); - const arg1Value = 3; - const arg1 = createSyncPromise(identityArg1)(arg1Value); - const arg2 = 2; - const arg3Value = 1; - const arg3 = createAsyncPromise(identityArg3)(arg3Value); + const argument1Value = 3; + const argument1 = createSyncPromise(identityArgument1)(argument1Value); + const argument2 = 2; + const argument3Value = 1; + const argument3 = createAsyncPromise(identityArgument3)(argument3Value); const initialAccValue = 10; const initialAcc = createAsyncPromise(identityAcc)(initialAccValue); - const inputValue = [arg1, arg2, arg3]; + const inputValue = [argument1, argument2, argument3]; const input = new Set(inputValue); - const inputValueResolved = [arg1Value, arg2, arg3Value]; + const inputValueResolved = [argument1Value, argument2, argument3Value]; const result = await areduceRight(asyncConcatenationFn, initialAcc)(input); const expectedResult = "10123"; expect(result).toBe(expectedResult); - mockFnExpectations(identityArg3, 1, arg3Value, arg3Value); - expect(identityArg3).toHaveBeenCalledTimes(1); - mockFnExpectations(identityArg1, 1, arg1Value, arg1Value); - expect(identityArg1).toHaveBeenCalledTimes(1); + mockFnExpectations(identityArgument3, 1, argument3Value, argument3Value); + expect(identityArgument3).toHaveBeenCalledTimes(1); + mockFnExpectations(identityArgument1, 1, argument1Value, argument1Value); + expect(identityArgument1).toHaveBeenCalledTimes(1); mockFnExpectations(identityAcc, 1, initialAccValue, initialAccValue); expect(identityAcc).toHaveBeenCalledTimes(1); expect(concatenationFn).toHaveBeenCalledTimes(3); - mockFnExpectations(concatenationFn, 1, "101", initialAccValue, arg3Value, 2, inputValueResolved); - mockFnExpectations(concatenationFn, 2, "1012", "101", arg2, 1, inputValueResolved); - mockFnExpectations(concatenationFn, 3, expectedResult, "1012", arg1Value, 0, inputValueResolved); + mockFnExpectations(concatenationFn, 1, "101", initialAccValue, argument3Value, 2, inputValueResolved); + mockFnExpectations(concatenationFn, 2, "1012", "101", argument2, 1, inputValueResolved); + mockFnExpectations(concatenationFn, 3, expectedResult, "1012", argument1Value, 0, inputValueResolved); }); it("should work for mixed list of promises and not as input and with non symmetrical operation", async () => { expect.assertions(12); const concatenationFn = concatenationReduceFnMock(jest, "sumFn"); - const identityArg1 = identityMock(jest, "identityArg1"); - const identityArg3 = identityMock(jest, "identityArg3"); - const arg1Value = 3; - const arg1 = createSyncPromise(identityArg1)(arg1Value); - const arg2 = 2; - const arg3Value = 1; - const arg3 = createAsyncPromise(identityArg3)(arg3Value); - const inputValue = [arg1, arg2, arg3]; + const identityArgument1 = identityMock(jest, "identityArgument1"); + const identityArgument3 = identityMock(jest, "identityArgument3"); + const argument1Value = 3; + const argument1 = createSyncPromise(identityArgument1)(argument1Value); + const argument2 = 2; + const argument3Value = 1; + const argument3 = createAsyncPromise(identityArgument3)(argument3Value); + const inputValue = [argument1, argument2, argument3]; const input = new Set(inputValue); - const inputValueResolved = [arg1Value, arg2, arg3Value]; + const inputValueResolved = [argument1Value, argument2, argument3Value]; const result = await areduceRight(concatenationFn)(input); const expectedResult = "123"; expect(result).toBe(expectedResult); - mockFnExpectations(identityArg3, 1, arg3Value, arg3Value); - expect(identityArg3).toHaveBeenCalledTimes(1); - mockFnExpectations(identityArg1, 1, arg1Value, arg1Value); - expect(identityArg1).toHaveBeenCalledTimes(1); + mockFnExpectations(identityArgument3, 1, argument3Value, argument3Value); + expect(identityArgument3).toHaveBeenCalledTimes(1); + mockFnExpectations(identityArgument1, 1, argument1Value, argument1Value); + expect(identityArgument1).toHaveBeenCalledTimes(1); expect(concatenationFn).toHaveBeenCalledTimes(2); - mockFnExpectations(concatenationFn, 1, "12", arg3Value, arg2, 1, inputValueResolved); - mockFnExpectations(concatenationFn, 2, expectedResult, "12", arg1Value, 0, inputValueResolved); + mockFnExpectations(concatenationFn, 1, "12", argument3Value, argument2, 1, inputValueResolved); + mockFnExpectations(concatenationFn, 2, expectedResult, "12", argument1Value, 0, inputValueResolved); }); it("should work for mixed list of promises and not as input and with non symmetrical operation with promise in reduce function", async () => { expect.assertions(12); const concatenationFn = concatenationReduceFnMock(jest, "sumFn"); const asyncConcatenationFn = createAsyncPromise(concatenationFn); - const identityArg1 = identityMock(jest, "identityArg1"); - const identityArg3 = identityMock(jest, "identityArg3"); - const arg1Value = 3; - const arg1 = createSyncPromise(identityArg1)(arg1Value); - const arg2 = 2; - const arg3Value = 1; - const arg3 = createAsyncPromise(identityArg3)(arg3Value); - const inputValue = [arg1, arg2, arg3]; + const identityArgument1 = identityMock(jest, "identityArgument1"); + const identityArgument3 = identityMock(jest, "identityArgument3"); + const argument1Value = 3; + const argument1 = createSyncPromise(identityArgument1)(argument1Value); + const argument2 = 2; + const argument3Value = 1; + const argument3 = createAsyncPromise(identityArgument3)(argument3Value); + const inputValue = [argument1, argument2, argument3]; const input = new Set(inputValue); - const inputValueResolved = [arg1Value, arg2, arg3Value]; + const inputValueResolved = [argument1Value, argument2, argument3Value]; const result = await areduceRight(asyncConcatenationFn)(input); const expectedResult = "123"; expect(result).toBe(expectedResult); - mockFnExpectations(identityArg3, 1, arg3Value, arg3Value); - expect(identityArg3).toHaveBeenCalledTimes(1); - mockFnExpectations(identityArg1, 1, arg1Value, arg1Value); - expect(identityArg1).toHaveBeenCalledTimes(1); + mockFnExpectations(identityArgument3, 1, argument3Value, argument3Value); + expect(identityArgument3).toHaveBeenCalledTimes(1); + mockFnExpectations(identityArgument1, 1, argument1Value, argument1Value); + expect(identityArgument1).toHaveBeenCalledTimes(1); expect(concatenationFn).toHaveBeenCalledTimes(2); - mockFnExpectations(concatenationFn, 1, "12", arg3Value, arg2, 1, inputValueResolved); - mockFnExpectations(concatenationFn, 2, expectedResult, "12", arg1Value, 0, inputValueResolved); + mockFnExpectations(concatenationFn, 1, "12", argument3Value, argument2, 1, inputValueResolved); + mockFnExpectations(concatenationFn, 2, expectedResult, "12", argument1Value, 0, inputValueResolved); }); }); diff --git a/__tests__/test-utils/promiseUtils.js b/__tests__/test-utils/promiseUtils.js index b4317a9..ffb3939 100644 --- a/__tests__/test-utils/promiseUtils.js +++ b/__tests__/test-utils/promiseUtils.js @@ -1,16 +1,19 @@ import { getError } from "./errorUtils"; const createAsyncPromise = ( - mapFn = (...mapFnArgs) => (mapFnArgs.length === 1 ? mapFnArgs[0] : mapFnArgs), + mapFn = (...mapFnArguments) => (mapFnArguments.length === 1 ? mapFnArguments[0] : mapFnArguments), successful = true -) => (...inputValueArgs) => +) => (...inputValueArguments) => new Promise((resolve, reject) => - setTimeout(() => (successful ? resolve(mapFn(...inputValueArgs)) : reject(getError(...inputValueArgs))), 100) + setTimeout( + () => (successful ? resolve(mapFn(...inputValueArguments)) : reject(getError(...inputValueArguments))), + 100 + ) ); const createSyncPromise = ( - mapFn = (...mapFnArgs) => (mapFnArgs.length === 1 ? mapFnArgs[0] : mapFnArgs), + mapFn = (...mapFnArguments) => (mapFnArguments.length === 1 ? mapFnArguments[0] : mapFnArguments), successful = true -) => async (...inputValueArgs) => - successful ? mapFn(...inputValueArgs) : Promise.reject(getError(...inputValueArgs)); +) => async (...inputValueArguments) => + successful ? mapFn(...inputValueArguments) : Promise.reject(getError(...inputValueArguments)); export { createAsyncPromise, createSyncPromise }; diff --git a/__tests__/util/afilterGeneric.js b/__tests__/util/afilterGeneric.js index 72a42a8..05faa30 100644 --- a/__tests__/util/afilterGeneric.js +++ b/__tests__/util/afilterGeneric.js @@ -79,7 +79,7 @@ describe("afilterGeneric tests", () => { } catch (e) { expect(e).toBeInstanceOf(Error); expect(e.message).toBe(getErrorMessage(inputValue)); - expect(filterFn).not.toBeCalled(); + expect(filterFn).not.toHaveBeenCalled(); } }); it("should work with promise and value as input", async () => { @@ -143,11 +143,11 @@ describe("afilterGeneric tests", () => { } catch (e) { expect(e).toBeInstanceOf(Error); expect(e.message).toBe(getErrorMessage(input2)); - expect(filterFn).not.toBeCalled(); + expect(filterFn).not.toHaveBeenCalled(); expect(increment).toHaveBeenCalledTimes(2); mockFnExpectations(increment, 1, 5, input1); mockFnExpectations(increment, 2, 6, input3); - expect(squareInPromise).not.toBeCalled(); + expect(squareInPromise).not.toHaveBeenCalled(); } }); it("should reject if function is rejected with promises as input in sequence", async () => { @@ -156,17 +156,17 @@ describe("afilterGeneric tests", () => { const input2 = 5; const dangerousFilterFn = getMockFn(jest)(n => n.first.second * n.first.second > 10, "dangerousFn"); const squareInPromise = squareMock(jest, "squareInPromise"); - const getObjFromInt = getMockFn(jest)(n => ({ first: { second: n } }), "getObjFromInt"); + const getObjectFromInt = getMockFn(jest)(n => ({ first: { second: n } }), "getObjectFromInt"); try { await afilterGeneric(true)(dangerousFilterFn)([ createAsyncPromise(squareInPromise)(input1), - createSyncPromise(getObjFromInt)(input2) + createSyncPromise(getObjectFromInt)(input2) ]); expect(true).toBe(false); } catch (e) { expect(e).toBeInstanceOf(TypeError); expect(e.message).toBe("Cannot read property 'second' of undefined"); - mockFnExpectations(getObjFromInt, 1, { first: { second: input2 } }, input2); + mockFnExpectations(getObjectFromInt, 1, { first: { second: input2 } }, input2); mockFnExpectations(squareInPromise, 1, 16, input1); expect(dangerousFilterFn).toHaveBeenCalledTimes(1); mockFnArgumentsExpectations(dangerousFilterFn, 1, 16, 0, [16, { first: { second: input2 } }]); @@ -178,17 +178,17 @@ describe("afilterGeneric tests", () => { const input2 = 5; const dangerousFilterFn = getMockFn(jest)(n => n.first.second * n.first.second > 10, "dangerousFn"); const squareInPromise = squareMock(jest, "squareInPromise"); - const getObjFromInt = getMockFn(jest)(n => ({ first: { second: n } }), "getObjFromInt"); + const getObjectFromInt = getMockFn(jest)(n => ({ first: { second: n } }), "getObjectFromInt"); try { await afilterGeneric()(dangerousFilterFn)([ createAsyncPromise(squareInPromise)(input1), - createSyncPromise(getObjFromInt)(input2) + createSyncPromise(getObjectFromInt)(input2) ]); expect(true).toBe(false); } catch (e) { expect(e).toBeInstanceOf(TypeError); expect(e.message).toBe("Cannot read property 'second' of undefined"); - mockFnExpectations(getObjFromInt, 1, { first: { second: input2 } }, input2); + mockFnExpectations(getObjectFromInt, 1, { first: { second: input2 } }, input2); mockFnExpectations(squareInPromise, 1, 16, input1); expect(dangerousFilterFn).toHaveBeenCalledTimes(2); mockFnArgumentsExpectations(dangerousFilterFn, 1, 16, 0, [16, { first: { second: input2 } }]); @@ -234,7 +234,7 @@ describe("afilterGeneric tests", () => { } catch (e) { expect(e).toBeInstanceOf(Error); expect(e.message).toBe(getErrorMessage([input1, 0, inputValue])); - expect(filterFn).not.toBeCalled(); + expect(filterFn).not.toHaveBeenCalled(); } }); it("should reject with rejected promise in sequence", async () => { @@ -249,7 +249,7 @@ describe("afilterGeneric tests", () => { } catch (e) { expect(e).toBeInstanceOf(Error); expect(e.message).toBe(getErrorMessage([input1, 0, inputValue])); - expect(filterFn).not.toBeCalled(); + expect(filterFn).not.toHaveBeenCalled(); } }); }); diff --git a/__tests__/util/amapGeneric.js b/__tests__/util/amapGeneric.js index 9b47af6..49ec9ab 100644 --- a/__tests__/util/amapGeneric.js +++ b/__tests__/util/amapGeneric.js @@ -58,7 +58,7 @@ describe("amapGeneric tests", () => { } catch (e) { expect(e).toBeInstanceOf(Error); expect(e.message).toBe(getErrorMessage(inputValue)); - expect(square).not.toBeCalled(); + expect(square).not.toHaveBeenCalled(); } }); it("should reject for failed promise as input in sequence", async () => { @@ -73,7 +73,7 @@ describe("amapGeneric tests", () => { } catch (e) { expect(e).toBeInstanceOf(Error); expect(e.message).toBe(getErrorMessage(inputValue)); - expect(square).not.toBeCalled(); + expect(square).not.toHaveBeenCalled(); } }); it("should work with promise and value as input", async () => { @@ -123,9 +123,9 @@ describe("amapGeneric tests", () => { } catch (e) { expect(e).toBeInstanceOf(Error); expect(e.message).toBe(getErrorMessage(input1)); - expect(square).not.toBeCalled(); + expect(square).not.toHaveBeenCalled(); mockFnExpectations(increment, 1, 6, input2); - expect(squareInPromise).not.toBeCalled(); + expect(squareInPromise).not.toHaveBeenCalled(); } }); it("should reject if function is rejected with promises as input", async () => { @@ -134,17 +134,17 @@ describe("amapGeneric tests", () => { const input2 = 5; const dangerousFn = getMockFn(jest)(n => n.first.second * n.first.second, "dangerousFn"); const squareInPromise = squareMock(jest, "squareInPromise"); - const getObjFromInt = getMockFn(jest)(n => ({ first: { second: n } }), "getObjFromInt"); + const getObjectFromInt = getMockFn(jest)(n => ({ first: { second: n } }), "getObjectFromInt"); try { await amapGeneric()(dangerousFn)([ createAsyncPromise(squareInPromise)(input1), - createSyncPromise(getObjFromInt)(input2) + createSyncPromise(getObjectFromInt)(input2) ]); expect(true).toBe(false); } catch (e) { expect(e).toBeInstanceOf(TypeError); expect(e.message).toBe("Cannot read property 'second' of undefined"); - mockFnExpectations(getObjFromInt, 1, { first: { second: input2 } }, input2); + mockFnExpectations(getObjectFromInt, 1, { first: { second: input2 } }, input2); mockFnExpectations(squareInPromise, 1, 16, input1); expect(dangerousFn).toHaveBeenCalledTimes(1); mockFnArgumentsExpectations(dangerousFn, 1, 16, 0, [16, { first: { second: input2 } }]); @@ -156,17 +156,17 @@ describe("amapGeneric tests", () => { const input2 = 5; const dangerousFn = getMockFn(jest)(async n => n.first.second * n.first.second, "dangerousFn"); const squareInPromise = squareMock(jest, "squareInPromise"); - const getObjFromInt = getMockFn(jest)(n => ({ first: { second: n } }), "getObjFromInt"); + const getObjectFromInt = getMockFn(jest)(n => ({ first: { second: n } }), "getObjectFromInt"); try { await amapGeneric()(dangerousFn)([ createAsyncPromise(squareInPromise)(input1), - createSyncPromise(getObjFromInt)(input2) + createSyncPromise(getObjectFromInt)(input2) ]); expect(true).toBe(false); } catch (e) { expect(e).toBeInstanceOf(TypeError); expect(e.message).toBe("Cannot read property 'second' of undefined"); - mockFnExpectations(getObjFromInt, 1, { first: { second: input2 } }, input2); + mockFnExpectations(getObjectFromInt, 1, { first: { second: input2 } }, input2); mockFnExpectations(squareInPromise, 1, 16, input1); expect(dangerousFn).toHaveBeenCalledTimes(2); mockFnArgumentsExpectations(dangerousFn, 1, 16, 0, [16, { first: { second: input2 } }]); @@ -182,17 +182,17 @@ describe("amapGeneric tests", () => { const input2 = 5; const dangerousFn = getMockFn(jest)(async n => n.first.second * n.first.second, "dangerousFn"); const squareInPromise = squareMock(jest, "squareInPromise"); - const getObjFromInt = getMockFn(jest)(n => ({ first: { second: n } }), "getObjFromInt"); + const getObjectFromInt = getMockFn(jest)(n => ({ first: { second: n } }), "getObjectFromInt"); try { await amapGeneric(true)(dangerousFn)([ createAsyncPromise(squareInPromise)(input1), - createSyncPromise(getObjFromInt)(input2) + createSyncPromise(getObjectFromInt)(input2) ]); expect(true).toBe(false); } catch (e) { expect(e).toBeInstanceOf(TypeError); expect(e.message).toBe("Cannot read property 'second' of undefined"); - mockFnExpectations(getObjFromInt, 1, { first: { second: input2 } }, input2); + mockFnExpectations(getObjectFromInt, 1, { first: { second: input2 } }, input2); mockFnExpectations(squareInPromise, 1, 16, input1); expect(dangerousFn).toHaveBeenCalledTimes(1); mockFnArgumentsExpectations(dangerousFn, 1, 16, 0, [16, { first: { second: input2 } }]); @@ -234,7 +234,7 @@ describe("amapGeneric tests", () => { } catch (e) { expect(e).toBeInstanceOf(Error); expect(e.message).toBe(getErrorMessage([input1, 0, inputValue])); - expect(square).not.toBeCalled(); + expect(square).not.toHaveBeenCalled(); } }); it("should reject with rejected promise traditional way", () => { @@ -249,8 +249,8 @@ describe("amapGeneric tests", () => { .catch(e => { expect(e).toBeInstanceOf(Error); expect(e.message).toBe(getErrorMessage([input1, 0, inputValue])); - expect(square).not.toBeCalled(); - expect(promiseMapFn).not.toBeCalled(); + expect(square).not.toHaveBeenCalled(); + expect(promiseMapFn).not.toHaveBeenCalled(); }); }); }); diff --git a/__tests__/util/extractArrayFromArgument.js b/__tests__/util/extractArrayFromArgument.js index 71d2705..2bd8c37 100644 --- a/__tests__/util/extractArrayFromArgument.js +++ b/__tests__/util/extractArrayFromArgument.js @@ -23,4 +23,4 @@ describe("extractArrayFromArgument tests", () => { const result = await extractArrayFromArgument(1); expect(result).toEqual([]); }); -}); \ No newline at end of file +}); diff --git a/gulpfile.js b/gulpfile.js index 9ee7240..86f341d 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -23,7 +23,7 @@ const banner = `/** gulp.task("clean", () => del(["dist", "*.js", "*.mjs", "*.map", "!gulpfile.js", "!babel.config.js"])); const getSourceFile = () => gulp.src(SOURCES), - getDest = () => gulp.dest("."), + getDestination = () => gulp.dest("."), rollupUmd = rollup( { onwarn(warning) { @@ -66,9 +66,9 @@ const getSourceFile = () => gulp.src(SOURCES), } ) ) - .pipe(getDest()) + .pipe(getDestination()) .pipe(rename({ extname: `.mjs` })) - .pipe(getDest()); + .pipe(getDestination()); gulp.task("es6modules", () => proceedEs6Modules()); @@ -83,7 +83,7 @@ gulp.task("es5modules", () => }) ) .pipe(sourcemaps.write(".")) - .pipe(getDest()) + .pipe(getDestination()) ); gulp.task("es5modulesMin", () => @@ -98,7 +98,7 @@ gulp.task("es5modulesMin", () => }) ) .pipe(sourcemaps.write(".")) - .pipe(getDest()) + .pipe(getDestination()) ); gulp.task("scripts", gulp.series("es5modulesMin", "es5modules", "es6modules")); diff --git a/jsconfig.json b/jsconfig.json new file mode 100644 index 0000000..f46caca --- /dev/null +++ b/jsconfig.json @@ -0,0 +1,4 @@ +{ + "compilerOptions": { "target": "esnext", "baseUrl": "src" }, + "exclude": ["node_modules"] +} diff --git a/package-lock.json b/package-lock.json index aabd3f7..38ad7ca 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1981,6 +1981,15 @@ } } }, + "clean-regexp": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/clean-regexp/-/clean-regexp-1.0.0.tgz", + "integrity": "sha1-jffHquUf02h06PjQW5GAvBGj/tc=", + "dev": true, + "requires": { + "escape-string-regexp": "^1.0.5" + } + }, "cli-cursor": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-2.1.0.tgz", @@ -2816,6 +2825,16 @@ "text-table": "^0.2.0" } }, + "eslint-ast-utils": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/eslint-ast-utils/-/eslint-ast-utils-1.1.0.tgz", + "integrity": "sha512-otzzTim2/1+lVrlH19EfQQJEhVJSu0zOb9ygb3iapN6UlyaDtyRq4b5U1FuW0v1lRa9Fp/GJyHkSwm6NqABgCA==", + "dev": true, + "requires": { + "lodash.get": "^4.4.2", + "lodash.zip": "^4.2.0" + } + }, "eslint-config-prettier": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-4.2.0.tgz", @@ -2825,6 +2844,51 @@ "get-stdin": "^6.0.0" } }, + "eslint-plugin-jest": { + "version": "22.5.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-22.5.1.tgz", + "integrity": "sha512-c3WjZR/HBoi4GedJRwo2OGHa8Pzo1EbSVwQ2HFzJ+4t2OoYM7Alx646EH/aaxZ+9eGcPiq0FT0UGkRuFFx2FHg==", + "dev": true + }, + "eslint-plugin-prettier": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-3.0.1.tgz", + "integrity": "sha512-/PMttrarPAY78PLvV3xfWibMOdMDl57hmlQ2XqFeA37wd+CJ7WSxV7txqjVPHi/AAFKd2lX0ZqfsOc/i5yFCSQ==", + "dev": true, + "requires": { + "prettier-linter-helpers": "^1.0.0" + } + }, + "eslint-plugin-unicorn": { + "version": "8.0.2", + "resolved": "https://registry.npmjs.org/eslint-plugin-unicorn/-/eslint-plugin-unicorn-8.0.2.tgz", + "integrity": "sha512-Ik2/Bt/PvPnf1lZgUnNFK2310XoRn/4LYiP5gkEPVDa4w9HCoii7I6SeKh2X5Rdp2WLy4eUiLcYtiBUp+q2IRw==", + "dev": true, + "requires": { + "clean-regexp": "^1.0.0", + "eslint-ast-utils": "^1.0.0", + "import-modules": "^1.1.0", + "lodash.camelcase": "^4.1.1", + "lodash.defaultsdeep": "^4.6.0", + "lodash.kebabcase": "^4.0.1", + "lodash.snakecase": "^4.0.1", + "lodash.topairs": "^4.3.0", + "lodash.upperfirst": "^4.2.0", + "reserved-words": "^0.1.2", + "safe-regex": "^2.0.1" + }, + "dependencies": { + "safe-regex": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/safe-regex/-/safe-regex-2.0.2.tgz", + "integrity": "sha512-rRALJT0mh4qVFIJ9HvfjKDN77F9vp7kltOpFFI/8e6oKyHFmmxz4aSkY/YVauRDe7U0RrHdw9Lsxdel3E19s0A==", + "dev": true, + "requires": { + "regexp-tree": "~0.1.1" + } + } + } + }, "eslint-scope": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-4.0.3.tgz", @@ -3137,6 +3201,12 @@ "integrity": "sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk=", "dev": true }, + "fast-diff": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/fast-diff/-/fast-diff-1.2.0.tgz", + "integrity": "sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w==", + "dev": true + }, "fast-json-stable-stringify": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz", @@ -4439,6 +4509,12 @@ } } }, + "import-modules": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/import-modules/-/import-modules-1.1.0.tgz", + "integrity": "sha1-dI23nFzEK7lwHvq0JPiU5yYA6dw=", + "dev": true + }, "imurmurhash": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", @@ -6003,12 +6079,54 @@ "integrity": "sha1-soqmKIorn8ZRA1x3EfZathkDMaY=", "dev": true }, + "lodash.defaultsdeep": { + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/lodash.defaultsdeep/-/lodash.defaultsdeep-4.6.0.tgz", + "integrity": "sha1-vsECT4WxvZbL6kBbI8FK1kQ6b4E=", + "dev": true + }, + "lodash.get": { + "version": "4.4.2", + "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz", + "integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk=", + "dev": true + }, + "lodash.kebabcase": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/lodash.kebabcase/-/lodash.kebabcase-4.1.1.tgz", + "integrity": "sha1-hImxyw0p/4gZXM7KRI/21swpXDY=", + "dev": true + }, + "lodash.snakecase": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/lodash.snakecase/-/lodash.snakecase-4.1.1.tgz", + "integrity": "sha1-OdcUo1NXFHg3rv1ktdy7Fr7Nj40=", + "dev": true + }, "lodash.sortby": { "version": "4.7.0", "resolved": "https://registry.npmjs.org/lodash.sortby/-/lodash.sortby-4.7.0.tgz", "integrity": "sha1-7dFMgk4sycHgsKG0K7UhBRakJDg=", "dev": true }, + "lodash.topairs": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/lodash.topairs/-/lodash.topairs-4.3.0.tgz", + "integrity": "sha1-O23qo31g+xFnE8RsXxfqGQ7EjWQ=", + "dev": true + }, + "lodash.upperfirst": { + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/lodash.upperfirst/-/lodash.upperfirst-4.3.1.tgz", + "integrity": "sha1-E2Xt9DFIBIHvDRxolXpe2Z1J984=", + "dev": true + }, + "lodash.zip": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/lodash.zip/-/lodash.zip-4.2.0.tgz", + "integrity": "sha1-7GZi5IlkCO1KtsVCo5kLcswIACA=", + "dev": true + }, "log-symbols": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-2.2.0.tgz", @@ -6955,6 +7073,15 @@ "integrity": "sha512-sXe5lSt2WQlCbydGETgfm1YBShgOX4HxQkFPvbxkcwgDvGDeqVau8h+12+lmSVlP3rHPz0oavfddSZg/q+Szjw==", "dev": true }, + "prettier-linter-helpers": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz", + "integrity": "sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==", + "dev": true, + "requires": { + "fast-diff": "^1.1.2" + } + }, "pretty-format": { "version": "24.8.0", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-24.8.0.tgz", @@ -7360,6 +7487,12 @@ "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==", "dev": true }, + "reserved-words": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/reserved-words/-/reserved-words-0.1.2.tgz", + "integrity": "sha1-AKCUD5jNUBrqqsMWQR2a3FKzGrE=", + "dev": true + }, "resolve": { "version": "1.10.1", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.10.1.tgz", diff --git a/package.json b/package.json index 92b88a1..5bfc244 100644 --- a/package.json +++ b/package.json @@ -37,11 +37,6 @@ "url": "https://github.com/Constantiner/fun-ctional/issues" }, "homepage": "https://github.com/Constantiner/fun-ctional#readme", - "prettier": { - "printWidth": 120, - "useTabs": true, - "tabWidth": 4 - }, "engines": { "node": ">=7.6", "npm": ">=5.2.0" @@ -55,6 +50,9 @@ "del": "^4.1.1", "eslint": "^5.16.0", "eslint-config-prettier": "^4.2.0", + "eslint-plugin-jest": "^22.5.1", + "eslint-plugin-prettier": "^3.0.1", + "eslint-plugin-unicorn": "^8.0.2", "gulp": "^4.0.1", "gulp-better-rollup": "^4.0.1", "gulp-rename": "^1.4.0", diff --git a/src/afilter.js b/src/afilter.js index 0046648..f6499a3 100644 --- a/src/afilter.js +++ b/src/afilter.js @@ -4,14 +4,14 @@ import afilterGeneric from "./util/afilterGeneric"; * An asynchronous version of filter over an iterable (afilter stays for async-filter). * * It gets an iterable of values (or promises) as input (or promise to resolve to iterable), - * resolves them, iterates over them with filter function - * (which returns boolean where true means current value will be included in resulting array) + * resolves them, iterates over them with filter function + * (which returns boolean where true means current value will be included in resulting array) * and returns a promise which resolves to an array of values (filtered input iterable). * * It allows asynchronous filtering point-free way and can be used with asynchronous compose functions. * * It uses Promise.all() under the hood. - * So if filtering function is asynchronous (returns a promise) all promises are being generated at once + * So if filtering function is asynchronous (returns a promise) all promises are being generated at once * and then resolved with Promise.all(). * So if any of promises will produce error (promise rejection) all the other promises will be invoked anyway. * The advantage of this method of invoking promises it will finish earlier than sequential filter (because of Promise.all()) diff --git a/src/afilterSeq.js b/src/afilterSeq.js index 4a5422b..42462e5 100644 --- a/src/afilterSeq.js +++ b/src/afilterSeq.js @@ -4,13 +4,13 @@ import afilterGeneric from "./util/afilterGeneric"; * An asynchronous version of filter over an iterable (afilterSeq stays for async-filter). * * It gets an iterable of values (or promises) as input (or promise to resolve to iterable), - * resolves them, iterates over them with filter function - * (which returns boolean where true means current value will be included in resulting array) + * resolves them, iterates over them with filter function + * (which returns boolean where true means current value will be included in resulting array) * and returns a promise which resolves to an array of values (filtered input iterable). * * It allows asynchronous filtering point-free way and can be used with asynchronous compose functions. * - * The difference from regular afilter is if filter function is asynchronous (returns a promise) + * The difference from regular afilter is if filter function is asynchronous (returns a promise) * every new invocation of filter function performs sequentially after resolving previous promise. * So if any of promises produces error (promise rejection) afilterSeq will not produce new promises and they won't be invoked. * diff --git a/src/amap.js b/src/amap.js index e19166a..b7d2879 100644 --- a/src/amap.js +++ b/src/amap.js @@ -9,7 +9,7 @@ import amapGeneric from "./util/amapGeneric"; * It allows asynchronous mapping point-free way and can be used with asynchronous compose functions. * * It uses Promise.all() under the hood. - * So if mapping function is asynchronous (returns a promise) all promises are being generated at once + * So if mapping function is asynchronous (returns a promise) all promises are being generated at once * and then resolved with Promise.all(). * So if any of promises will produce error (promise rejection) all the other promises will be invoked. * The advantage of this method of invoking promises it will finish earlier than sequential map (because of Promise.all()) diff --git a/src/amapSeq.js b/src/amapSeq.js index 3c2dcd1..86016b1 100644 --- a/src/amapSeq.js +++ b/src/amapSeq.js @@ -8,7 +8,7 @@ import amapGeneric from "./util/amapGeneric"; * * It allows asynchronous mapping point-free way and can be used with asynchronous compose functions. * - * The difference from regular amap is if map function is asynchronous (returns a promise) + * The difference from regular amap is if map function is asynchronous (returns a promise) * every new invocation of map function performs sequentially after resolving previous promise. * So if any of promises produces error (promise rejection) amapSeq will not produce new promises and they won't be invoked. * diff --git a/src/applyFns.js b/src/applyFns.js index 8d4af27..aa5afc4 100644 --- a/src/applyFns.js +++ b/src/applyFns.js @@ -24,6 +24,6 @@ import extractResolvedArguments from "./util/extractResolvedArguments"; * @returns {(value : Promise|any) => Promise} A function which expects any value as input (resolving to Promise) and returns a Promise. */ export default (...fns) => async value => { - const val = await Promise.resolve(value); - return Promise.all(extractResolvedArguments(fns).map(fn => fn(val))); + const resolvedValue = await Promise.resolve(value); + return Promise.all(extractResolvedArguments(fns).map(fn => fn(resolvedValue))); }; diff --git a/src/areduce.js b/src/areduce.js index c33a332..98412c7 100644 --- a/src/areduce.js +++ b/src/areduce.js @@ -1,4 +1,4 @@ -import { getReducerArgs, resolveArrayFromInput } from "./util/reducer"; +import { getReducerArguments, resolveArrayFromInput } from "./util/reducer"; /** * Asynchronous composable version of reduce method for iterables ("a" stays for "asynchronous"). @@ -27,5 +27,5 @@ import { getReducerArgs, resolveArrayFromInput } from "./util/reducer"; * @returns {(iterable : Promise|Iterable.<*>) => Promise} A function which expects an iterable * (or promise resolved to iterable) and returns a Promise. */ -export default (...args) => async iterable => - Array.prototype.reduce.apply(await resolveArrayFromInput(iterable), getReducerArgs(args)); +export default (...args) => async iterable => + Array.prototype.reduce.apply(await resolveArrayFromInput(iterable), getReducerArguments(args)); diff --git a/src/areduceRight.js b/src/areduceRight.js index 054b1c4..a9a400b 100644 --- a/src/areduceRight.js +++ b/src/areduceRight.js @@ -1,4 +1,4 @@ -import { getReducerArgs, resolveArrayFromInput } from "./util/reducer"; +import { getReducerArguments, resolveArrayFromInput } from "./util/reducer"; /** * Asynchronous composable version of reduceRight method for iterables ("a" stays for "asynchronous"). @@ -28,4 +28,4 @@ import { getReducerArgs, resolveArrayFromInput } from "./util/reducer"; * (or promise resolved to iterable) and returns a Promise. */ export default (...args) => async iterable => - Array.prototype.reduceRight.apply(await resolveArrayFromInput(iterable), getReducerArgs(args)); + Array.prototype.reduceRight.apply(await resolveArrayFromInput(iterable), getReducerArguments(args)); diff --git a/src/fun-ctional.js b/src/fun-ctional.js index 28ee45c..8a2e39b 100644 --- a/src/fun-ctional.js +++ b/src/fun-ctional.js @@ -1,3 +1,4 @@ +/* eslint-disable unicorn/filename-case */ import acatch from "./acatch"; import acompose from "./acompose"; import afilter from "./afilter"; diff --git a/src/util/extractArrayFromArgument.js b/src/util/extractArrayFromArgument.js index 89e3f9f..cd2271d 100644 --- a/src/util/extractArrayFromArgument.js +++ b/src/util/extractArrayFromArgument.js @@ -1,10 +1,11 @@ +/* eslint-disable unicorn/prefer-spread */ /** * Returns a promise which resolved to array of values from a passed iterable. * An iterable can be a promise to resolve to iterable and then to array. * - * @param {Promise|Iterable.<*>} arg Is iterable or promise to resolve to. + * @param {Promise|Iterable.<*>} arrayLike Is iterable or promise to resolve to. * @returns {Promise} A promise to resolve to resulting array. */ -const extractArrayFromArgument = async arg => Array.from(await Promise.resolve(arg)); +const extractArrayFromArgument = async arrayLike => Array.from(await Promise.resolve(arrayLike)); export default extractArrayFromArgument; diff --git a/src/util/extractResolvedArguments.js b/src/util/extractResolvedArguments.js index 8a7d5f0..eddf2d4 100644 --- a/src/util/extractResolvedArguments.js +++ b/src/util/extractResolvedArguments.js @@ -8,7 +8,6 @@ import isIterable from "./isIterable"; * If if consists of one element and this element is an iterable returns array from it. * @returns {Promise} Resulting array of arguments. */ -const extractResolvedArguments = args => - args ? (args.length === 1 && isIterable(args[0]) ? Array.from(args[0]) : args) : []; +const extractResolvedArguments = args => (args ? (args.length === 1 && isIterable(args[0]) ? [...args[0]] : args) : []); -export default extractResolvedArguments; \ No newline at end of file +export default extractResolvedArguments; diff --git a/src/util/isIterable.js b/src/util/isIterable.js index a7165a6..3c09293 100644 --- a/src/util/isIterable.js +++ b/src/util/isIterable.js @@ -1,9 +1,9 @@ /** * Checks if parameter is an iterable. - * + * * @param {any} obj is target to check. * @returns {boolean} Result of checking. */ -const isIterable = obj => Array.isArray(obj) || ((obj || obj === "") && typeof obj[Symbol.iterator] === "function");; +const isIterable = obj => Array.isArray(obj) || ((obj || obj === "") && typeof obj[Symbol.iterator] === "function"); export default isIterable; diff --git a/src/util/reducer.js b/src/util/reducer.js index e2d46a1..1db3d45 100644 --- a/src/util/reducer.js +++ b/src/util/reducer.js @@ -5,11 +5,11 @@ const resolveArrayFromInput = async iterable => Promise.all(await extractArrayFr const reducer = reduceFn => (acc, current, index, array) => Promise.resolve(acc).then(acc => reduceFn(acc, current, index, array)); -const getReducerArgs = args => { +const getReducerArguments = args => { const effectiveReduceFn = reducer(args[0]); - const effectiveArgs = Array.from(args); - effectiveArgs[0] = effectiveReduceFn; - return effectiveArgs; + const effectiveArguments = [...args]; + effectiveArguments[0] = effectiveReduceFn; + return effectiveArguments; }; -export { getReducerArgs, resolveArrayFromInput }; +export { getReducerArguments, resolveArrayFromInput };