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
Prev Previous commit
Next Next commit
chore: remove .toReturnWith() matcher
  • Loading branch information
EduardoSCosta committed Aug 30, 2022
commit da3ef6ce1ed4053c4a57c65b510f0f460a7061f8
145 changes: 0 additions & 145 deletions packages/expect/src/__tests__/__snapshots__/spyMatchers.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2033,148 +2033,3 @@ Expected: not <g>undefined</>

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

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

Expected: <g>undefined</>
Received: function call threw an error

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

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

Expected: <g>undefined</>
Received: function call threw an error

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

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

Expected: <g>"foo"</>

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

exports[`toReturnWith returnedWith incomplete recursive calls are handled properly 1`] = `
<d>expect(</><r>jest.fn()</><d>).</>toReturnWith<d>(</><g>expected</><d>)</>

Expected: <g>undefined</>
Received
1: function call has not returned yet
2: function call has not returned yet
3: function call has not returned yet

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

exports[`toReturnWith returnedWith works with more calls than the limit 1`] = `
<d>expect(</><r>jest.fn()</><d>).</>toReturnWith<d>(</><g>expected</><d>)</>

Expected: <g>"bar"</>
Received
1: <r>"foo1"</>
2: <r>"foo2"</>
3: <r>"foo3"</>

Number of returns: <r>6</>
`;

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

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

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

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

Expected: <g>"foo"</>

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

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

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

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

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

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

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

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

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

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

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

Expected: <g>Map {"a" => "b", "b" => "a"}</>
Received: <r>Map {1 => 2, 2 => 1}</>

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

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

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

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

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

Expected: <g>Set {3, 4}</>
Received: <r>Set {1, 2}</>

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

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

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

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

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

Expected: <g>"bar"</>
Received: <r>"foo"</>

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

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

Expected: not <g>undefined</>

Number of returns: <r>1</>
`;
4 changes: 1 addition & 3 deletions packages/expect/src/__tests__/spyMatchers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,6 @@ describe('toHaveReturnedTimes', () => {
'toHaveLastReturnedWith',
'nthReturnedWith',
'toHaveNthReturnedWith',
'toReturnWith',
'toHaveReturnedWith',
].forEach(returnedWith => {
const caller = function (
Expand Down Expand Up @@ -1039,8 +1038,7 @@ describe('toHaveReturnedTimes', () => {
).toThrowErrorMatchingSnapshot();
});

const basicReturnedWith = ['toHaveReturnedWith', 'toReturnWith'];
if (basicReturnedWith.indexOf(returnedWith) >= 0) {
if (returnedWith === 'toHaveReturnedWith') {
describe('returnedWith', () => {
test('works with more calls than the limit', () => {
const fn = jest.fn();
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 @@ -1152,7 +1152,6 @@ const spyMatchers: MatchersObject = {
toHaveReturned: createToReturnMatcher('toHaveReturned'),
toHaveReturnedTimes: createToReturnTimesMatcher('toHaveReturnedTimes'),
toHaveReturnedWith: createToReturnWithMatcher('toHaveReturnedWith'),
toReturnWith: createToReturnWithMatcher('toReturnWith'),
};

const isMock = (received: any) =>
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 @@ -294,10 +294,6 @@ export interface Matchers<R extends void | Promise<void>> {
toMatchObject(
expected: Record<string, unknown> | Array<Record<string, unknown>>,
): R;
/**
* Ensure that a mock function has returned a specified value at least once.
*/
toReturnWith(expected: unknown): R;
/**
* Use to test that objects have the same types as well as structure.
*/
Expand Down
5 changes: 2 additions & 3 deletions packages/jest-types/__typetests__/expect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,9 @@ expectType<void>(expect(jest.fn()).toHaveReturnedTimes(3));
expectError(expect(jest.fn()).toHaveReturnedTimes('twice'));
expectError(expect(jest.fn()).toHaveReturnedTimes(true));

expectType<void>(expect(jest.fn()).toReturnWith('value'));
expectError(expect(jest.fn()).toReturnWith());
expectType<void>(expect(jest.fn()).toHaveReturnedWith(123));
expectError(expect(jest.fn()).toHaveReturnedWith());
expectType<void>(expect(jest.fn()).toHaveReturnedWith('value'));
expectType<void>(expect(jest.fn()).toHaveReturnedWith(123));

expectType<void>(expect(jest.fn()).lastReturnedWith('value'));
expectError(expect(jest.fn()).lastReturnedWith());
Expand Down