-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Feature Request: Expose return values of calls to mock functions #5738
Comments
I think that would be a nice feature. PR welcome! 🙂 |
I'll work on this in the next few days. I suspect the code change itself will be fairly easy, and the bulk of the effort will be updating unit tests to thoroughly verify it. |
Can anyone help me out with this error when running
It seems completely unrelated to the changes I'm making. Here's the branch with my changes: https://github.com/UselessPickles/jest/tree/mock_return_values |
Hmmm... there's also several unit tests failing in master. I guess the build is generally a bit broken even before I made any changes. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Do you want to request a feature or report a bug?
Feature
What is the current behavior?
There is currently no way to access the return values that were returned by calls to mock functions.
What is the expected behavior?
When using
jest.mock()
to simply wrap a method for the purpose of "spying" on calls to the method (check if it's called, inspect the params it was called with, etc), it would also be very useful to have access to the list of return values that have been returned by calls to the mock function. This would be equivalent tosinon
'sspy.returnValues
: http://sinonjs.org/releases/v2.0.0/spies/The basic design of this would involve adding "returnValues" to
MockFunctionState
as such:And updating
_makeComponent
to push the final returned value onto the newreturnValues
array.(see https://github.com/facebook/jest/blob/master/packages/jest-mock/src/index.js)
If there are no major "gotchas" to this plan, then I would volunteer to create a PR with these changes.
Please provide your exact Jest configuration and mention your Jest, node,
yarn/npm version and operating system.
Irrelevant
The text was updated successfully, but these errors were encountered: