Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
chore: remove .lastReturnedWith() matcher
  • Loading branch information
EduardoSCosta committed Aug 30, 2022
commit d873fe92742322ff29e22ef53413120040559d0e
147 changes: 2 additions & 145 deletions packages/expect/src/__tests__/__snapshots__/spyMatchers.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,148 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

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

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

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

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

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

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

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

Expected: <g>"foo"</>

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

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

Expected: <g>0</>
Received
3: function call has not returned yet
-> 4: function call has not returned yet

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

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

Expected: not <g>"foo3"</>
Received
2: <r>"foo2"</>
-> 3: <d>"foo3"</>

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

exports[`lastReturnedWith works only on spies or jest.fn 1`] = `
<d>expect(</><r>received</><d>).</>lastReturnedWith<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[`lastReturnedWith works when not called 1`] = `
<d>expect(</><r>jest.fn()</><d>).</>lastReturnedWith<d>(</><g>expected</><d>)</>

Expected: <g>"foo"</>

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Expected: not <g>undefined</>

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

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

Expand Down Expand Up @@ -1234,7 +1091,7 @@ Expected: <g>"foo"</>
Number of returns: <r>0</>
`;

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

Expected: <g>0</>
Expand All @@ -1246,7 +1103,7 @@ Number of returns: <r>0</>
Number of calls: <r>4</>
`;

exports[`toHaveLastReturnedWith lastReturnedWith works with three calls 1`] = `
exports[`toHaveLastReturnedWith toHaveLastReturnedWith works with three calls 1`] = `
<d>expect(</><r>jest.fn()</><d>).</>not<d>.</>toHaveLastReturnedWith<d>(</><g>expected</><d>)</>

Expected: not <g>"foo3"</>
Expand Down
6 changes: 2 additions & 4 deletions packages/expect/src/__tests__/spyMatchers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,6 @@ describe('toHaveReturnedTimes', () => {
});

[
'lastReturnedWith',
'toHaveLastReturnedWith',
'nthReturnedWith',
'toHaveNthReturnedWith',
Expand Down Expand Up @@ -1208,9 +1207,8 @@ describe('toHaveReturnedTimes', () => {
});
}

const lastReturnedWith = ['toHaveLastReturnedWith', 'lastReturnedWith'];
if (lastReturnedWith.indexOf(returnedWith) >= 0) {
describe('lastReturnedWith', () => {
if (returnedWith === 'toHaveLastReturnedWith') {
describe('toHaveLastReturnedWith', () => {
test('works with three calls', () => {
const fn = jest.fn();
fn.mockReturnValueOnce('foo1');
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 = {
lastReturnedWith: createLastReturnedMatcher('lastReturnedWith'),
nthReturnedWith: createNthReturnedWithMatcher('nthReturnedWith'),
toHaveBeenCalled: createToBeCalledMatcher('toHaveBeenCalled'),
toHaveBeenCalledTimes: createToBeCalledTimesMatcher('toHaveBeenCalledTimes'),
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>> {
/**
* Ensure that the last call to a mock function has returned a specified value.
*/
lastReturnedWith(expected: unknown): R;
/**
* Ensure that the nth call to a mock function has returned a specified value.
*/
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 @@ -230,10 +230,9 @@ 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());
expectType<void>(expect(jest.fn()).toHaveLastReturnedWith(123));
expectError(expect(jest.fn()).toHaveLastReturnedWith());
expectType<void>(expect(jest.fn()).toHaveLastReturnedWith('value'));
expectType<void>(expect(jest.fn()).toHaveLastReturnedWith(123));

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