Skip to content

Commit

Permalink
chore: add more tests for toHaveLastReturnedWith and `lastReturnedW…
Browse files Browse the repository at this point in the history
…ith` matchers (#13384)
  • Loading branch information
mrazauskas committed Oct 4, 2022
1 parent 8e96af6 commit ae8a5a2
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
Expand Up @@ -242,6 +242,29 @@ Received
Number of returns: <r>3</>
`;

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

Expected: <g>undefined</>
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 returnedWith works with more calls than the limit 1`] = `
<d>expect(</><r>jest.fn()</><d>).</>lastReturnedWith<d>(</><g>expected</><d>)</>

Expected: <g>"bar"</>
Received
5: <r>"foo5"</>
-> 6: <r>"foo6"</>

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

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

Expand Down Expand Up @@ -2060,6 +2083,29 @@ Received
Number of returns: <r>3</>
`;

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

Expected: <g>undefined</>
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[`toHaveLastReturnedWith returnedWith works with more calls than the limit 1`] = `
<d>expect(</><r>jest.fn()</><d>).</>toHaveLastReturnedWith<d>(</><g>expected</><d>)</>

Expected: <g>"bar"</>
Received
5: <r>"foo5"</>
-> 6: <r>"foo6"</>

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

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

Expand Down
7 changes: 6 additions & 1 deletion packages/expect/src/__tests__/spyMatchers.test.ts
Expand Up @@ -1023,7 +1023,12 @@ describe.each([
).toThrowErrorMatchingSnapshot();
});

const basicReturnedWith = ['toHaveReturnedWith', 'toReturnWith'];
const basicReturnedWith = [
'toHaveLastReturnedWith',
'lastReturnedWith',
'toHaveReturnedWith',
'toReturnWith',
];
if (basicReturnedWith.indexOf(returnedWith) >= 0) {
describe('returnedWith', () => {
test('works with more calls than the limit', () => {
Expand Down

0 comments on commit ae8a5a2

Please sign in to comment.