# Jest cannot log after tests are done

Classification: timing-race
Frameworks: Jest
Canonical: https://automationtester.in/failures/jest-cannot-log-after-tests

## Recognizable error

```text
Cannot log after tests are done. Did you forget to wait for something async
```

## What it means

Asynchronous work continued after Jest considered the test complete and attempted to write output later.

## Ranked causes, checks, and fixes

### 1. A promise was not returned or awaited

The test function ends before the asynchronous branch settles.

Diagnostic: Find unawaited calls and callbacks that create promises in the failing test.

Fix: Return or await the promise and assert after it resolves.

### 2. A timer or subscription was not cleaned up

Intervals, event listeners, or observers remain active after teardown.

Diagnostic: Run with open-handle detection and inspect created timers and subscriptions.

Fix: Clear timers and unsubscribe in afterEach or the component cleanup path.

### 3. A mocked callback fires after teardown

The mock schedule outlives the test's expected lifecycle.

Diagnostic: Inspect fake timers, delayed callbacks, and pending request mocks.

Fix: Flush the intended work or cancel it before restoring mocks.

## Prevention

- Await every async user journey.
- Clean up timers and subscriptions.
- Treat open handles as test failures.

## Primary references

- [Jest asynchronous testing](https://jestjs.io/docs/asynchronous)

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