# Unhandled promise rejection in tests

Classification: flaky
Frameworks: Jest, Playwright, CI
Canonical: https://automationtester.in/failures/unhandled-promise-rejection

## Recognizable error

```text
UnhandledPromiseRejection
```

## What it means

An asynchronous operation rejected without a handler attached in the test or application lifecycle.

## Ranked causes, checks, and fixes

### 1. A promise was started without awaiting it

The rejection escapes after the test moves on.

Diagnostic: Trace every created promise in the failing path and find the missing await or return.

Fix: Await the operation and assert its success or rejection explicitly.

### 2. Cleanup rejects after teardown

A closed page, socket, or server can cause late asynchronous failures.

Diagnostic: Inspect teardown ordering and open handles.

Fix: Stop producers before closing their dependencies and await cleanup.

### 3. An event handler throws asynchronously

Framework callbacks can reject outside the test's main promise chain.

Diagnostic: Capture application errors and identify the originating event.

Fix: Handle the error in the application and expose an observable failure state.

## Prevention

- Fail on unhandled rejections.
- Await cleanup.
- Keep asynchronous ownership explicit.

## Primary references

- [Node.js unhandled rejections](https://nodejs.org/api/process.html#event-unhandledrejection)

Triage this failure locally: https://automationtester.in/tools/test-failure-triage