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

Fix bugs with mock/spy result tracking of recursive functions. #6381

Merged
merged 30 commits into from Oct 31, 2018
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
dfeeeab
Fix bugs with mock/spy result tracking of recursive functions.
UselessPickles Jun 2, 2018
495253b
Update CHANGELOG
UselessPickles Jun 2, 2018
46ef216
Fix invalid type specification
UselessPickles Jun 2, 2018
7de2a48
Finally figured out the flow type for "undefined"
UselessPickles Jun 2, 2018
fe9a05b
Revert unnecessary restructuring of unit tests
UselessPickles Jun 2, 2018
714d9e9
Add more code comments
UselessPickles Jun 2, 2018
2037127
Move CHANGELOG entry to "master" section
UselessPickles Jun 3, 2018
6d9abbd
Fix prettier error
UselessPickles Jun 3, 2018
78abee0
Merge branch 'master' into recursive_mock_results
UselessPickles Jun 5, 2018
0e72d35
Convert "isThrow" boolean to "type" string enum.
UselessPickles Jun 5, 2018
0bfd292
Update mock_serializer unit tests
UselessPickles Jun 5, 2018
705af41
Add "BREAKING" indicator to changelog
UselessPickles Jun 5, 2018
c9779c8
Define a type alias for the type of MockFunctionResult.type
UselessPickles Jun 5, 2018
55fddc1
Merge from master
UselessPickles Jun 6, 2018
ef24642
Merge branch 'master' into recursive_mock_results
UselessPickles Jun 29, 2018
e8f8756
Merge branch 'master' into recursive_mock_results
UselessPickles Jul 3, 2018
aa90f56
Re-introduce deprecated MockFunctionResult.isThrow
UselessPickles Jul 6, 2018
9dff29c
Fix linting error
UselessPickles Jul 6, 2018
b1aff31
Merge from master
UselessPickles Jul 6, 2018
715612c
Update mock_serializer tests to account for re-introduced `isThrow`
UselessPickles Jul 7, 2018
9679583
Fix lint errors
UselessPickles Jul 7, 2018
c107c9b
Fix flow type
UselessPickles Jul 7, 2018
803f93b
Fix flow type more correctly
UselessPickles Jul 7, 2018
244f30c
Merge remote-tracking branch 'origin/master' into recursive_mock_results
rickhanlonii Jul 12, 2018
57deef3
Rm breaking
rickhanlonii Jul 12, 2018
c2da0a5
Remove deprecated "isThrow" property
UselessPickles Oct 31, 2018
2786a49
Merge branch 'recursive_mock_results' of https://github.com/UselessPi…
UselessPickles Oct 31, 2018
42e7c42
Move changelog entry to the "master" section
UselessPickles Oct 31, 2018
6ef2461
Merge branch 'master' into recursive_mock_results
UselessPickles Oct 31, 2018
c56a325
Fix CHANGELOG entry again (and mark it as BREAKING)
UselessPickles Oct 31, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,8 @@
## master

### Fixes
- `[jest-mock]` Fix bugs with mock/spy result tracking of recursive functions ([#6381](https://github.com/facebook/jest/pull/6381)

## 23.1.0

### Features
Expand Down
142 changes: 142 additions & 0 deletions packages/expect/src/__tests__/__snapshots__/spy_matchers.test.js.snap
Expand Up @@ -149,6 +149,14 @@ Expected mock function \\"named-mock\\" to have last returned:
But it was <red>not called</>"
`;

exports[`lastReturnedWith incomplete recursive calls are handled properly 1`] = `
"<dim>expect(</><red>jest.fn()</><dim>).lastReturnedWith(</><green>expected</><dim>)</>

Expected mock function to have last returned:
<green>0</>
But the last call <red>has not returned yet</>"
`;

exports[`lastReturnedWith works only on spies or jest.fn 1`] = `
"<dim>expect(</><red>jest.fn()</><dim>)[.not].lastReturnedWith(</><dim>)</>

Expand Down Expand Up @@ -237,6 +245,15 @@ But the last call returned:
<red>\\"foo\\"</>"
`;

exports[`lastReturnedWith works with three calls 1`] = `
"<dim>expect(</><red>jest.fn()</><dim>).not.lastReturnedWith(</><green>expected</><dim>)</>

Expected mock function to not have last returned:
<green>\\"foo3\\"</>
But it last returned exactly:
<red>\\"foo3\\"</>"
`;

exports[`lastReturnedWith works with undefined 1`] = `
"<dim>expect(</><red>jest.fn()</><dim>).not.lastReturnedWith(</><green>expected</><dim>)</>

Expand Down Expand Up @@ -406,6 +423,40 @@ Expected mock function \\"named-mock\\" first call to have returned with:
But it was <red>not called</>"
`;

exports[`nthReturnedWith incomplete recursive calls are handled properly 1`] = `
"<dim>expect(</><red>jest.fn()</><dim>).nthReturnedWith(</><green>expected</><dim>)</>

Expected mock function first call to have returned with:
<green>6</>
But the first call <red>has not returned yet</>"
`;

exports[`nthReturnedWith incomplete recursive calls are handled properly 2`] = `
"<dim>expect(</><red>jest.fn()</><dim>).nthReturnedWith(</><green>expected</><dim>)</>

Expected mock function second call to have returned with:
<green>3</>
But the second call <red>has not returned yet</>"
`;

exports[`nthReturnedWith incomplete recursive calls are handled properly 3`] = `
"<dim>expect(</><red>jest.fn()</><dim>).not.nthReturnedWith(</><green>expected</><dim>)</>

Expected mock function third call to not have returned with:
<green>1</>
But the third call returned exactly:
<red>1</>"
`;

exports[`nthReturnedWith incomplete recursive calls are handled properly 4`] = `
"<dim>expect(</><red>jest.fn()</><dim>).not.nthReturnedWith(</><green>expected</><dim>)</>

Expected mock function 4th call to not have returned with:
<green>0</>
But the 4th call returned exactly:
<red>0</>"
`;

exports[`nthReturnedWith should reject non integer nth value 1`] = `"nth value <red>0.1</> must be a positive integer greater than <green>0</>"`;

exports[`nthReturnedWith should reject nth value greater than number of calls 1`] = `
Expand Down Expand Up @@ -1437,6 +1488,14 @@ Expected mock function \\"named-mock\\" to have last returned:
But it was <red>not called</>"
`;

exports[`toHaveLastReturnedWith incomplete recursive calls are handled properly 1`] = `
"<dim>expect(</><red>jest.fn()</><dim>).toHaveLastReturnedWith(</><green>expected</><dim>)</>

Expected mock function to have last returned:
<green>0</>
But the last call <red>has not returned yet</>"
`;

exports[`toHaveLastReturnedWith works only on spies or jest.fn 1`] = `
"<dim>expect(</><red>jest.fn()</><dim>)[.not].toHaveLastReturnedWith(</><dim>)</>

Expand Down Expand Up @@ -1525,6 +1584,15 @@ But the last call returned:
<red>\\"foo\\"</>"
`;

exports[`toHaveLastReturnedWith works with three calls 1`] = `
"<dim>expect(</><red>jest.fn()</><dim>).not.toHaveLastReturnedWith(</><green>expected</><dim>)</>

Expected mock function to not have last returned:
<green>\\"foo3\\"</>
But it last returned exactly:
<red>\\"foo3\\"</>"
`;

exports[`toHaveLastReturnedWith works with undefined 1`] = `
"<dim>expect(</><red>jest.fn()</><dim>).not.toHaveLastReturnedWith(</><green>expected</><dim>)</>

Expand Down Expand Up @@ -1558,6 +1626,40 @@ Expected mock function \\"named-mock\\" first call to have returned with:
But it was <red>not called</>"
`;

exports[`toHaveNthReturnedWith incomplete recursive calls are handled properly 1`] = `
"<dim>expect(</><red>jest.fn()</><dim>).toHaveNthReturnedWith(</><green>expected</><dim>)</>

Expected mock function first call to have returned with:
<green>6</>
But the first call <red>has not returned yet</>"
`;

exports[`toHaveNthReturnedWith incomplete recursive calls are handled properly 2`] = `
"<dim>expect(</><red>jest.fn()</><dim>).toHaveNthReturnedWith(</><green>expected</><dim>)</>

Expected mock function second call to have returned with:
<green>3</>
But the second call <red>has not returned yet</>"
`;

exports[`toHaveNthReturnedWith incomplete recursive calls are handled properly 3`] = `
"<dim>expect(</><red>jest.fn()</><dim>).not.toHaveNthReturnedWith(</><green>expected</><dim>)</>

Expected mock function third call to not have returned with:
<green>1</>
But the third call returned exactly:
<red>1</>"
`;

exports[`toHaveNthReturnedWith incomplete recursive calls are handled properly 4`] = `
"<dim>expect(</><red>jest.fn()</><dim>).not.toHaveNthReturnedWith(</><green>expected</><dim>)</>

Expected mock function 4th call to not have returned with:
<green>0</>
But the 4th call returned exactly:
<red>0</>"
`;

exports[`toHaveNthReturnedWith should reject non integer nth value 1`] = `"nth value <red>0.1</> must be a positive integer greater than <green>0</>"`;

exports[`toHaveNthReturnedWith should reject nth value greater than number of calls 1`] = `
Expand Down Expand Up @@ -1735,6 +1837,12 @@ Expected mock function \\"named-mock\\" not to have returned, but it returned:
<red>42</>"
`;

exports[`toHaveReturned incomplete recursive calls are handled properly 1`] = `
"<dim>expect(</><red>jest.fn()</><dim>).toHaveReturned(</><dim>)</>

Expected mock function to have returned."
`;

exports[`toHaveReturned passes when at least one call does not throw 1`] = `
"<dim>expect(</><red>jest.fn()</><dim>).not.toHaveReturned(</><dim>)</>

Expand Down Expand Up @@ -1850,6 +1958,12 @@ exports[`toHaveReturnedTimes includes the custom mock name in the error message
Expected mock function \\"named-mock\\" to have returned <green>one time</>, but it returned <red>two times</>."
`;

exports[`toHaveReturnedTimes incomplete recursive calls are handled properly 1`] = `
"<dim>expect(</><red>jest.fn()</><dim>).not.toHaveReturnedTimes(</><green>2</><dim>)</>

Expected mock function not to have returned <green>two times</>, but it returned exactly <red>two times</>."
`;

exports[`toHaveReturnedTimes only accepts a number argument 1`] = `
"<dim>expect(</><red>received</><dim>)[.not].toHaveReturnedTimes(</><green>expected</><dim>)</>

Expand Down Expand Up @@ -1936,6 +2050,14 @@ Expected mock function \\"named-mock\\" to have returned:
But it did <red>not return</>."
`;

exports[`toHaveReturnedWith incomplete recursive calls are handled properly 1`] = `
"<dim>expect(</><red>jest.fn()</><dim>).toHaveReturnedWith(</><green>expected</><dim>)</>

Expected mock function to have returned:
<green>undefined</>
But it did <red>not return</>."
`;

exports[`toHaveReturnedWith works only on spies or jest.fn 1`] = `
"<dim>expect(</><red>jest.fn()</><dim>)[.not].toHaveReturnedWith(</><dim>)</>

Expand Down Expand Up @@ -2093,6 +2215,12 @@ Expected mock function \\"named-mock\\" not to have returned, but it returned:
<red>42</>"
`;

exports[`toReturn incomplete recursive calls are handled properly 1`] = `
"<dim>expect(</><red>jest.fn()</><dim>).toReturn(</><dim>)</>

Expected mock function to have returned."
`;

exports[`toReturn passes when at least one call does not throw 1`] = `
"<dim>expect(</><red>jest.fn()</><dim>).not.toReturn(</><dim>)</>

Expand Down Expand Up @@ -2208,6 +2336,12 @@ exports[`toReturnTimes includes the custom mock name in the error message 1`] =
Expected mock function \\"named-mock\\" to have returned <green>one time</>, but it returned <red>two times</>."
`;

exports[`toReturnTimes incomplete recursive calls are handled properly 1`] = `
"<dim>expect(</><red>jest.fn()</><dim>).not.toReturnTimes(</><green>2</><dim>)</>

Expected mock function not to have returned <green>two times</>, but it returned exactly <red>two times</>."
`;

exports[`toReturnTimes only accepts a number argument 1`] = `
"<dim>expect(</><red>received</><dim>)[.not].toReturnTimes(</><green>expected</><dim>)</>

Expand Down Expand Up @@ -2294,6 +2428,14 @@ Expected mock function \\"named-mock\\" to have returned:
But it did <red>not return</>."
`;

exports[`toReturnWith incomplete recursive calls are handled properly 1`] = `
"<dim>expect(</><red>jest.fn()</><dim>).toReturnWith(</><green>expected</><dim>)</>

Expected mock function to have returned:
<green>undefined</>
But it did <red>not return</>."
`;

exports[`toReturnWith works only on spies or jest.fn 1`] = `
"<dim>expect(</><red>jest.fn()</><dim>)[.not].toReturnWith(</><dim>)</>

Expand Down