Skip to content

Commit

Permalink
Lodash: Remove completely from jest-console package (#42355)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla authored Jul 12, 2022
1 parent 7d5e47d commit 25cf5df
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 21 deletions.
3 changes: 1 addition & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions packages/jest-console/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 5 additions & 9 deletions packages/jest-console/src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { forEach } from 'lodash';

/**
* Internal dependencies
*/
Expand All @@ -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 }` );
Expand Down Expand Up @@ -47,4 +43,4 @@ const setConsoleMethodSpy = ( matcherName, methodName ) => {
afterEach( assertExpectedCalls );
};

forEach( supportedMatchers, setConsoleMethodSpy );
Object.entries( supportedMatchers ).forEach( setConsoleMethodSpy );
15 changes: 7 additions & 8 deletions packages/jest-console/src/matchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import { matcherHint, printExpected, printReceived } from 'jest-matcher-utils';
import { isEqual, reduce, some } from 'lodash';

/**
* Internal dependencies
Expand Down Expand Up @@ -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() ) +
Expand All @@ -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 {
Expand Down

0 comments on commit 25cf5df

Please sign in to comment.