DEV Community

Cover image for How to find which test warns unhandledPromiseRejection in jest
Peramanathan
Peramanathan

Posted on

How to find which test warns unhandledPromiseRejection in jest

unhandledPromiseRejectionWarning

From the above image can you tell which test suite is warning about unhandledPromiseRejection. Is it the one above the warning message or one below the warning message?

As most of you, me too wrongly guessed the test suite above the warning message warns about unhandledPromiseRejection. That eat up quite sometime since every time I re-run the tests, the warning seems to happen in different test suite module.

How did I figure out the it is the test suite below the unhandledPromiseRejection warning message is one that suffers?

I have added the following code in the jest's setupFilesAfterEnv file:

process.on('unhandledRejection', reason => {
  throw reason
})
Enter fullscreen mode Exit fullscreen mode

which logged the error trace
when I run the tests with

node --trace-uncaught node_modules/.bin/jest --runInBand --no-cache
Enter fullscreen mode Exit fullscreen mode

Latest comments (0)