-
-
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
[object Object] thrown when using mockRejectedValue() #7396
Comments
Hey @foxbunny, thanks for using Jest and for the detailed report! If I were to guess, something in your app code is throwing when you don't expect it to (I've dealt with this a lot when dealing with generators, it's super frustrating) If you can trim this down to something reproducible that shows it's a bug in jest I'm happy to take a look and re-open |
@rickhanlonii I figured out what it's doing. It's actually trapping an unhandled promise rejection. Is this by design? |
Not sure, @SimenB do you know? |
If you don't handle the rejection (a
|
@SimenB Thanks. I've upgraded to 23 meanwhile, and indeed, as you say, it shows the object being thrown. Is it considered an anti-pattern to let promise rejections go unhandled? |
Yes. Node itself will crash in the future when you do it, similar to uncaught errors. |
OK, thanks for your time and explanations. 👍 |
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. |
🐛 Bug Report
In some cases (I was not able to determine when and why), jest will fail a test with a message that looks like this:
In one of the tests, I was able to make it pass by changing the location of the mock:
In the above example (using Vue),
action.submitForm('form')
will force the submit event on a form and that triggers a call todata.renameList()
which is mocked here.In another test, I ran into the same issue:
Moving the mock to the line just above form submission does not work in this case. I've marked the line that I suspect leads to the exception based on what wallaby's coverage reports say. The exception cannot be trapped in any way from either the test code or the application code (I've tried putting
try catch
around the whole test to no avail.The
await nextTick()
is function that wrapssetTimeout()
in aPromise
to allow Vue to re-render the interface after state change.Point of failure (according to wallaby) depends on where the
mockRejectedValue()
is called:In the second case, the code that is invoked as a result of
action.leaveField()
is completely unrelated to the mocked function.In all cases, there are multiple calls to
mockResolvedValue()
in at least one of the previous tests, and there is a call tomockClear()
made before each test.To Reproduce
Steps to reproduce the behavior: n/a
Expected behavior
I expect that, regardless of where the
mockRejectedValue()
is called, the test would always succeed.Link to repl or repo (highly encouraged)
I was not able to create a small test case for this as even in this project,
mockRejectedValue()
works as expected in most cases.Run
npx envinfo --preset jest
Cannot install envinfo
OS: Windows 10 64bit
NodeJS: v8.11.1
NPM: v5.6.0
package.json deps:
babelrc:
jest.config.js:
The text was updated successfully, but these errors were encountered: