-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Unhandled rejections cause test script exit #4794
Comments
I assume the test result might be cached and being skipped, thus you're not seeing the failure when you're running all tests -- or there might be a bug in jest obscuring this issue. Nevertheless, this appears like it should be a handled rejection. You're handling it by Please fill out the issue template so we have all the necessary (and relevant) information to diagnose this further. |
OK, I'm happy to go off and fill in the issue template, but I had come to the conclusion that this was indeed an unhandled rejection -- Enzyme will call That's my understanding anyway, could well be incorrect! But if I'm right, that's not a bug with CRA, and my question was really whether there was a recommended way of writing the above test in CRA, particularly given that it's especially rigorous about unhandled rejections. |
Is this a bug report?More of a discussion/question really Did you try recovering your dependencies?Yes Which terms did you search for in User Guide?Unhandled rejection Environment
Steps to Reproduce(Write your steps here:)
Expected Behavior (and Actual Behavior)
|
Oh I'm sorry, I must not have looked closely enough -- I didn't see you are rethrowing the exception: throw e // rethrow so it gets handled by a generic unhandled promise rejection handler (e.g. Sentry) Then yes, per your original question this is the intended behavior because Node will crash anyway. We're just getting our users used to this earlier. If you catch an error that you want Sentry to report, you should report that error manually. Handling the error by reporting it to Sentry shouldn't stop your application from crashing, as you probably re-throw it there anyway. Thank you so much for filling out the template though! I should've looked more closely. 😅 |
In the browser environment, do we think that's better than just letting the promise "crash" and have it scooped up in a global handler? I kinda see an appeal in one unified place to report errors, rather than duplicating that at various places across the codebase. And it also plays nicely with the out-of-the box CRA error reporting in dev mode. So yeah, I appreciate that Node is getting really picky about it, so there's not really much to be done, but it seems a bit unfortunate to have to choose an error handling strategy to appease where the tests are being run, rather than the production code. Are there other reasons to report errors manually? |
I agree centralizing the handling of exceptions is nice, but I think the best way to handle this would be an error boundary (because it's not really unhandled if you're handling). Maybe toss an ErrorBoundary on the root of your
I agree with this, but it's not easy to draw this line -- and Node plans to crash on even a handled unhandled rejection (via the on event). I think this is best fixed by an ErrorBoundary. |
Alas, I had a try with Another option is for us to change our test so that we explicitly handle
|
Sigh, you're right. I'll re-open this as a proposal but I'm not sure the best path forward for this. Anyway, I don't see us changing this in the near-term so I'd suggest your test to look for that rejection. |
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs. |
This issue has been automatically closed because it has not had any recent activity. If you have a question or comment, please open a new issue. |
We're getting an error with one of our tests in our CRA app. Our test looks a bit like the following:
However, it blows up on
npm test
with:This behaviour appears to be because there is an unhandled rejection, and in
react-scripts/scripts/test.js
:So, I guess I wanted to understand whether what we're trying to do in our test is bad -- we have an unhandled rejection, but that's intentional, and not a problem in the browser environment (we have a global error handler that will deal with it). Is CRA being overly enthusiastic in causing the script to crash in these cases? Should we be dealing with things in a different way?
The other oddity is that most of the time, when all the tests in our actual app's test suite are run together, the test passes. It's only when run in isolation that we trigger the
unhandledRejection
event listener and the script exits. Any ideas on why that might be the case?The text was updated successfully, but these errors were encountered: