Skip to content

Support testing the unhandled promise rejection #5796

@kibertoad

Description

@kibertoad

Clear and concise description of the problem

Currently vitest fails a test run if it detects an unhandled rejection having been thrown:

Vitest caught 1 unhandled error during the test run.
This might cause false positive tests. Resolve unhandled errors to make sure your tests are not affected.

However, sometimes this is a desireable behaviour, especially when we are testing global unhandled rejection handlers.

Suggested solution

Several options are possible:

  • Only report as a problem unhandled rejections that were not handled during the test execution (e. g. if there is no `process.on('unhandledRejection' handler that would consume the event);
  • Make it possible to mark tests as expecting the unhandled rejections (e. g. syntax similar to expect.assertions(1) - expect.unhandledRejections(1))

Alternative

No response

Additional context

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    p3-minor-bugAn edge case that only affects very specific usage (priority)

    Type

    No type

    Projects

    Status

    P2 - 3

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions