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

Remove aliased matchers #13192

Closed
Closed
Prev Previous commit
Next Next commit
chore: remove .lastCalledWith() matcher
  • Loading branch information
EduardoSCosta committed Aug 30, 2022
commit 8f39d3f91e85f79e4cad70624fffd268673e7b86
191 changes: 0 additions & 191 deletions packages/expect/src/__tests__/__snapshots__/spyMatchers.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,196 +1,5 @@
// Jest Snapshot v1, https:https://goo.gl/fbAQLP

exports[`lastCalledWith includes the custom mock name in the error message 1`] = `
<d>expect(</><r>named-mock</><d>).</>not<d>.</>lastCalledWith<d>(</><g>...expected</><d>)</>

Expected: not <g>"foo"</>, <g>"bar"</>

Number of calls: <r>1</>
`;

exports[`lastCalledWith works only on spies or jest.fn 1`] = `
<d>expect(</><r>received</><d>).</>lastCalledWith<d>(</><g>...expected</><d>)</>

<b>Matcher error</>: <r>received</> value must be a mock or spy function

Received has type: function
Received has value: <r>[Function fn]</>
`;

exports[`lastCalledWith works when not called 1`] = `
<d>expect(</><r>jest.fn()</><d>).</>lastCalledWith<d>(</><g>...expected</><d>)</>

Expected: <g>"foo"</>, <g>"bar"</>

Number of calls: <r>0</>
`;

exports[`lastCalledWith works with Immutable.js objects 1`] = `
<d>expect(</><r>jest.fn()</><d>).</>not<d>.</>lastCalledWith<d>(</><g>...expected</><d>)</>

Expected: not <g>Immutable.Map {"a": {"b": "c"}}</>, <g>Immutable.Map {"a": {"b": "c"}}</>

Number of calls: <r>1</>
`;

exports[`lastCalledWith works with Map 1`] = `
<d>expect(</><r>jest.fn()</><d>).</>not<d>.</>lastCalledWith<d>(</><g>...expected</><d>)</>

Expected: not <g>Map {1 => 2, 2 => 1}</>

Number of calls: <r>1</>
`;

exports[`lastCalledWith works with Map 2`] = `
<d>expect(</><r>jest.fn()</><d>).</>lastCalledWith<d>(</><g>...expected</><d>)</>

<g>- Expected</>
<r>+ Received</>

<d> Map {</>
<g>- "a" => "b",</>
<g>- "b" => "a",</>
<r>+ 1 => 2,</>
<r>+ 2 => 1,</>
<d> }</>,

Number of calls: <r>1</>
`;

exports[`lastCalledWith works with Set 1`] = `
<d>expect(</><r>jest.fn()</><d>).</>not<d>.</>lastCalledWith<d>(</><g>...expected</><d>)</>

Expected: not <g>Set {1, 2}</>

Number of calls: <r>1</>
`;

exports[`lastCalledWith works with Set 2`] = `
<d>expect(</><r>jest.fn()</><d>).</>lastCalledWith<d>(</><g>...expected</><d>)</>

<g>- Expected</>
<r>+ Received</>

<d> Set {</>
<g>- 3,</>
<g>- 4,</>
<r>+ 1,</>
<r>+ 2,</>
<d> }</>,

Number of calls: <r>1</>
`;

exports[`lastCalledWith works with arguments that don't match 1`] = `
<d>expect(</><r>jest.fn()</><d>).</>lastCalledWith<d>(</><g>...expected</><d>)</>

Expected: <g>"foo"</>, <g>"bar"</>
Received: <d>"foo"</>, <r>"bar1"</>

Number of calls: <r>1</>
`;

exports[`lastCalledWith works with arguments that don't match in number of arguments 1`] = `
<d>expect(</><r>jest.fn()</><d>).</>lastCalledWith<d>(</><g>...expected</><d>)</>

Expected: <g>"foo"</>, <g>"bar"</>
Received: <d>"foo"</>, <d>"bar"</>, <r>"plop"</>

Number of calls: <r>1</>
`;

exports[`lastCalledWith works with arguments that don't match in size even if one is an optional matcher 1`] = `
<d>expect(</><r>jest.fn()</><d>).</>lastCalledWith<d>(</><g>...expected</><d>)</>

Expected: <g>"foo"</>, <g>optionalFn<></>
Received: <d>"foo"</>

Number of calls: <r>1</>
`;

exports[`lastCalledWith works with arguments that don't match with matchers 1`] = `
<d>expect(</><r>jest.fn()</><d>).</>lastCalledWith<d>(</><g>...expected</><d>)</>

Expected: <g>Any<String></>, <g>Any<Number></>
Received: <d>"foo"</>, <r>"bar"</>

Number of calls: <r>1</>
`;

exports[`lastCalledWith works with arguments that don't match with matchers even when argument is undefined 1`] = `
<d>expect(</><r>jest.fn()</><d>).</>lastCalledWith<d>(</><g>...expected</><d>)</>

Expected: <g>"foo"</>, <g>Any<String></>
Received: <d>"foo"</>, <r>undefined</>

Number of calls: <r>1</>
`;

exports[`lastCalledWith works with arguments that match 1`] = `
<d>expect(</><r>jest.fn()</><d>).</>not<d>.</>lastCalledWith<d>(</><g>...expected</><d>)</>

Expected: not <g>"foo"</>, <g>"bar"</>

Number of calls: <r>1</>
`;

exports[`lastCalledWith works with arguments that match with matchers 1`] = `
<d>expect(</><r>jest.fn()</><d>).</>not<d>.</>lastCalledWith<d>(</><g>...expected</><d>)</>

Expected: not <g>Any<String></>, <g>Any<String></>
Received: <r>0</>, <r>["foo", "bar"]</>

Number of calls: <r>1</>
`;

exports[`lastCalledWith works with many arguments 1`] = `
<d>expect(</><r>jest.fn()</><d>).</>not<d>.</>lastCalledWith<d>(</><g>...expected</><d>)</>

Expected: not <g>"foo"</>, <g>"bar"</>
Received
2: <d>"foo"</>, <r>"bar1"</>
-> 3: <d>"foo"</>, <d>"bar"</>

Number of calls: <r>3</>
`;

exports[`lastCalledWith works with many arguments that don't match 1`] = `
<d>expect(</><r>jest.fn()</><d>).</>lastCalledWith<d>(</><g>...expected</><d>)</>

Expected: <g>"foo"</>, <g>"bar"</>
Received
2: <d>"foo"</>, <r>"bar2"</>
-> 3: <d>"foo"</>, <r>"bar3"</>

Number of calls: <r>3</>
`;

exports[`lastCalledWith works with trailing undefined arguments 1`] = `
<d>expect(</><r>jest.fn()</><d>).</>lastCalledWith<d>(</><g>...expected</><d>)</>

Expected: <g>"foo"</>
Received: <d>"foo"</>, <r>undefined</>

Number of calls: <r>1</>
`;

exports[`lastCalledWith works with trailing undefined arguments if requested by the match query 1`] = `
<d>expect(</><r>jest.fn()</><d>).</>not<d>.</>lastCalledWith<d>(</><g>...expected</><d>)</>

Expected: not <g>"foo"</>, <g>undefined</>

Number of calls: <r>1</>
`;

exports[`lastCalledWith works with trailing undefined arguments when explicitely requested as optional by matcher 1`] = `
<d>expect(</><r>jest.fn()</><d>).</>not<d>.</>lastCalledWith<d>(</><g>...expected</><d>)</>

Expected: not <g>"foo"</>, <g>optionalFn<></>
Received: <r>0</>, <r>["foo", undefined]</>

Number of calls: <r>1</>
`;

exports[`lastReturnedWith a call that throws is not considered to have returned 1`] = `
<d>expect(</><r>jest.fn()</><d>).</>lastReturnedWith<d>(</><g>expected</><d>)</>

Expand Down
2 changes: 0 additions & 2 deletions packages/expect/src/__tests__/spyMatchers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ describe('toHaveBeenCalledTimes', () => {
});

[
'lastCalledWith',
'toHaveBeenLastCalledWith',
'nthCalledWith',
'toHaveBeenNthCalledWith',
Expand Down Expand Up @@ -434,7 +433,6 @@ describe('toHaveBeenCalledTimes', () => {
});

const basicCalledWith = [
'lastCalledWith',
'toHaveBeenLastCalledWith',
'toHaveBeenCalledWith',
];
Expand Down
1 change: 0 additions & 1 deletion packages/expect/src/spyMatchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,6 @@ const createNthReturnedWithMatcher = (matcherName: string) =>
};

const spyMatchers: MatchersObject = {
lastCalledWith: createLastCalledWithMatcher('lastCalledWith'),
lastReturnedWith: createLastReturnedMatcher('lastReturnedWith'),
nthCalledWith: createNthCalledWithMatcher('nthCalledWith'),
nthReturnedWith: createNthReturnedWithMatcher('nthReturnedWith'),
Expand Down
4 changes: 0 additions & 4 deletions packages/expect/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,6 @@ type PromiseMatchers = {
};

export interface Matchers<R extends void | Promise<void>> {
/**
* Ensures the last call to a mock function was provided specific args.
*/
lastCalledWith(...expected: Array<unknown>): R;
/**
* Ensure that the last call to a mock function has returned a specified value.
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-haste-map/src/crawlers/__tests__/node.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ describe('node crawler', () => {
roots: ['/project/fruits', '/project/vegetables'],
});

expect(childProcess.spawn).lastCalledWith('find', [
expect(childProcess.spawn).toHaveBeenLastCalledWith('find', [
'/project/fruits',
'/project/vegetables',
'-type',
Expand Down Expand Up @@ -266,7 +266,7 @@ describe('node crawler', () => {
roots: ['/project/fruits'],
});

expect(childProcess.spawn).lastCalledWith(
expect(childProcess.spawn).toHaveBeenLastCalledWith(
'find',
['.', '-type', 'f', '(', '-iname', '*.ts', '-o', '-iname', '*.js', ')'],
{cwd: expect.any(String)},
Expand Down
13 changes: 3 additions & 10 deletions packages/jest-types/__typetests__/expect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,28 +195,21 @@ expectType<void>(expect(() => {}).toThrow(new Error('error')));

expectType<void>(expect(jest.fn()).toHaveBeenCalled());
expectError(expect(jest.fn()).toHaveBeenCalled('value'));
expectType<void>(expect(jest.fn()).toHaveBeenCalled());
expectError(expect(jest.fn()).toHaveBeenCalled(false));

expectType<void>(expect(jest.fn()).toHaveBeenCalledTimes(1));
expectError(expect(jest.fn()).toHaveBeenCalledTimes('twice'));
expectError(expect(jest.fn()).toHaveBeenCalledTimes());
expectType<void>(expect(jest.fn()).toHaveBeenCalledTimes(3));
expectError(expect(jest.fn()).toHaveBeenCalledTimes('twice'));
expectError(expect(jest.fn()).toHaveBeenCalledTimes(true));
expectError(expect(jest.fn()).toHaveBeenCalledTimes());

expectType<void>(expect(jest.fn()).toHaveBeenCalledWith());
expectType<void>(expect(jest.fn()).toHaveBeenCalledWith('value'));
expectType<void>(expect(jest.fn()).toHaveBeenCalledWith('value', 123));
expectType<void>(expect(jest.fn()).toHaveBeenCalledWith());
expectType<void>(expect(jest.fn()).toHaveBeenCalledWith(123));
expectType<void>(expect(jest.fn()).toHaveBeenCalledWith('value'));
expectType<void>(expect(jest.fn()).toHaveBeenCalledWith(123, 'value'));

expectType<void>(expect(jest.fn()).lastCalledWith());
expectType<void>(expect(jest.fn()).lastCalledWith('value'));
expectType<void>(expect(jest.fn()).lastCalledWith('value', 123));
expectType<void>(expect(jest.fn()).toHaveBeenLastCalledWith());
expectType<void>(expect(jest.fn()).toHaveBeenLastCalledWith(123));
expectType<void>(expect(jest.fn()).toHaveBeenLastCalledWith('value'));
expectType<void>(expect(jest.fn()).toHaveBeenLastCalledWith(123, 'value'));

expectType<void>(expect(jest.fn()).nthCalledWith(2));
Expand Down