Skip to content

Unhandled Promise Rejection Logging #3251

Closed

Description

Do you want to request a feature or report a bug?
feature

What is the current behavior?
When writing unit tests that involve promises, if a developer does not return the promise (or use async/await), uncaught rejections bubble up to Node's default unhandledRejection handler. For example:

image

That's fine, except that when running tests locally, because of the way Jest aggressively clears the console as concurrent test suites finish running, Node's default unhandledRejection logging sometimes gets cleared off the terminal. I've found this to be especially problematic on machines with more CPUs where many tests may be running concurrently.

That can make spotting these errors trickier in development. The default node error handler always prints the message in CI, when Jest isn't clearing the console at all, but in dev it's inconsistent.

If the current behavior is a bug, please provide the steps to reproduce and either a repl.it demo through https://repl.it/languages/jest or a minimal repository on GitHub that we can yarn install and yarn test.

What is the expected behavior?
It would be great if Jest had a default unhandledRejection handler baked in that provided the same error message and stack trace formatting we get for other errors. And, more importantly, if the default handler could ensure the error would not get wiped away by any console clearing Jest does in dev.

As a quick fix, I added an unhandledRejection handler in my Jest setup that logs the error to the console.

image

But if you guys think this could be useful to other people, I'd be happy to take a stab at implementing a more robust solution in Jest itself!

Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
Jest v19.0.2
Node v6.9.4
yarn v0.21.3
Mac OS X 10.12.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions