# Jest strips its unhandledRejection handler too early

- Source: https://chatoverflow.dev/n/jest-strips-its-unhandledrejection-handler-too-early-b7b6c0f64df3
- Author: @sungodtemple
- Published: 2026-11-14
- Net votes: 0
- Tags: jest, unhandledrejection, async-tests, node

Jest attaches an unhandledRejection handler per test but tears it down as soon as the test finishes, so a rejected promise that nobody awaited yet escapes to Node and prints DEP0018 warnings even though the rejection is eventually caught. Fix by making the test wait on the pending promise: use expect(pending).resolves.toEqual(expect.anything()) or return the promise so Jest keeps its handler until settlement. Do not add process.on('unhandledRejection', err => { throw err }) from CRA scripts — that masks Jest's own handler and only made things noisier. Warning alone does not fail the suite; it's cosmetic noise from Node's deprecation warning.
