From db999d590ddbbc622422319383a2cdba81207f6f Mon Sep 17 00:00:00 2001 From: Marin Atanasov Date: Tue, 12 Jul 2022 12:16:05 +0300 Subject: [PATCH] Lodash: Remove completely from jest-console package --- package-lock.json | 3 +-- packages/jest-console/package.json | 3 +-- packages/jest-console/src/index.js | 14 +++++--------- packages/jest-console/src/matchers.js | 15 +++++++-------- 4 files changed, 14 insertions(+), 21 deletions(-) diff --git a/package-lock.json b/package-lock.json index 022d39b2cc6432..180c1aa08814a1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17426,8 +17426,7 @@ "dev": true, "requires": { "@babel/runtime": "^7.16.0", - "jest-matcher-utils": "^27.4.2", - "lodash": "^4.17.21" + "jest-matcher-utils": "^27.4.2" } }, "@wordpress/jest-preset-default": { diff --git a/packages/jest-console/package.json b/packages/jest-console/package.json index 755d268c012c0b..f80717c9f71644 100644 --- a/packages/jest-console/package.json +++ b/packages/jest-console/package.json @@ -33,8 +33,7 @@ "types": "types", "dependencies": { "@babel/runtime": "^7.16.0", - "jest-matcher-utils": "^27.4.2", - "lodash": "^4.17.21" + "jest-matcher-utils": "^27.4.2" }, "peerDependencies": { "jest": ">=27" diff --git a/packages/jest-console/src/index.js b/packages/jest-console/src/index.js index 0664e1c9ae1b1f..84cdb6f1d73ad2 100644 --- a/packages/jest-console/src/index.js +++ b/packages/jest-console/src/index.js @@ -1,8 +1,3 @@ -/** - * External dependencies - */ -import { forEach } from 'lodash'; - /** * Internal dependencies */ @@ -12,10 +7,11 @@ import supportedMatchers from './supported-matchers'; /** * Sets spy on the console object's method to make it possible to fail test when method called without assertion. * - * @param {string} matcherName Name of Jest matcher. - * @param {string} methodName Name of console method. + * @param {Array} args + * @param {string} args."0" Name of console method. + * @param {string} args."1" Name of Jest matcher. */ -const setConsoleMethodSpy = ( matcherName, methodName ) => { +const setConsoleMethodSpy = ( [ methodName, matcherName ] ) => { const spy = jest .spyOn( console, methodName ) .mockName( `console.${ methodName }` ); @@ -47,4 +43,4 @@ const setConsoleMethodSpy = ( matcherName, methodName ) => { afterEach( assertExpectedCalls ); }; -forEach( supportedMatchers, setConsoleMethodSpy ); +Object.entries( supportedMatchers ).forEach( setConsoleMethodSpy ); diff --git a/packages/jest-console/src/matchers.js b/packages/jest-console/src/matchers.js index 9e334f1ec992ee..078ef47fb1da55 100644 --- a/packages/jest-console/src/matchers.js +++ b/packages/jest-console/src/matchers.js @@ -2,7 +2,6 @@ * External dependencies */ import { matcherHint, printExpected, printReceived } from 'jest-matcher-utils'; -import { isEqual, reduce, some } from 'lodash'; /** * Internal dependencies @@ -33,12 +32,13 @@ const createToHaveBeenCalledMatcher = }; }; -const createToHaveBeenCalledWith = - ( matcherName, methodName ) => - ( received, ...expected ) => { +const createToHaveBeenCalledWith = ( matcherName, methodName ) => + function ( received, ...expected ) { const spy = received[ methodName ]; const calls = spy.mock.calls; - const pass = some( calls, ( objects ) => isEqual( objects, expected ) ); + const pass = calls.some( ( objects ) => + this.equals( objects, expected ) + ); const message = pass ? () => matcherHint( `.not${ matcherName }`, spy.getMockName() ) + @@ -63,9 +63,8 @@ const createToHaveBeenCalledWith = }; expect.extend( - reduce( - supportedMatchers, - ( result, matcherName, methodName ) => { + Object.entries( supportedMatchers ).reduce( + ( result, [ methodName, matcherName ] ) => { const matcherNameWith = `${ matcherName }With`; return {