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

[jest-mock] Return value is not recorded if mock implementation throws an error #5761

Closed
UselessPickles opened this issue Mar 8, 2018 · 4 comments · Fixed by #5764
Closed

Comments

@UselessPickles
Copy link
Contributor

UselessPickles commented Mar 8, 2018

Do you want to request a feature or report a bug?
Bug in new feature that I created :(

What is the current behavior?
If a jest mock function throws an error, the .mock.returnValues array is not updated with an entry for that call to the mock. This causes the returnValues array to become out of sync with all other parallel arrays in the structure (calls, instances, etc).

Original new feature ticket: #5738
Original new feature PR: #5752

If the current behavior is a bug, please provide the steps to reproduce
Should be obvious. I'll add a new unit test to reproduce it before fixing it.

What is the expected behavior?
The the parallel arrays in the mock function's mock structure should always have matching lengths. When a mock function implementation throws an error, a value of undefined should be pushed onto the mock.returnValues array.

Please provide your exact Jest configuration and mention your Jest, node,
yarn/npm version and operating system.

Irrelevant

@UselessPickles
Copy link
Contributor Author

I thought of this while lying in bed this morning, then discovered that my previous PR had already been merged :(

I'll create a new PR for this in the next day or two.

It also got me thinking that it would be nice to also maintain an array of errors thrown by calls to the mock. Any objections to including this new feature at the same time?

@rickhanlonii
Copy link
Member

Great preemptive find @UselessPickles

@UselessPickles
Copy link
Contributor Author

@rickhanlonii Thanks. Does this balance out my bad karma for introducing the bug in the first place?

@SimenB Do you want to be involved with this issue since you reviewed my previous PR for this feature?

@github-actions
Copy link

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.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants