Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Lodash: Remove completely from jest-console package #42355

Merged
merged 1 commit into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


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