Jest: Test does not fail when promise throws and error is not caught, contrary to documentation.

Created on 7 Mar 2017  路  5Comments  路  Source: facebook/jest

Do you want to request a feature or report a bug?
Report a bug.

What is the current behavior?
A promise that throws without being caught shows an unhandled promise rejection error in the console but the test passes.

screen shot 2017-03-07 at 13 47 35

If the current behavior is a bug, please provide the steps to reproduce and either a repl.it demo through https://repl.it/languages/jest or a minimal repository on GitHub that we can yarn install and yarn test.
https://github.com/leonaves/yarn-promise-bug/

What is the expected behavior?
As per https://facebook.github.io/jest/docs/tutorial-async.html#error-handling, the test should fail:

Note that if a Promise throws and the error is not handled, the test will fail.

Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
Jest version 19.0.2, default configuration (see repo). Node v6.10.0 LTS. Yarn v0.21.3.

Most helpful comment

So if you _forget_ to return the promise there is no way to have Jest fail because of the error thrown?

All 5 comments

I wouldn't know where to start submitting a PR for this, but if someone could point me in the right direction to get the ball rolling, I'd be happy to attempt to submit a fix for this myself.

You must return that promise

Embarrassing...

So if you _forget_ to return the promise there is no way to have Jest fail because of the error thrown?

We catch them during the test run now (and fail the test), but if it fails outside of a test run, we don't.

I wonder if we should stop uninstalling the handler at the end of tests. Or at least install a separate one between runs.

https://github.com/facebook/jest/blob/cf2b9e80a0b099c2f861660fd9cf589848106fa1/packages/jest-jasmine2/src/jasmine/Env.js#L247-L248

Was this page helpful?
0 / 5 - 0 ratings

Related issues

StephanBijzitter picture StephanBijzitter  路  3Comments

paularmstrong picture paularmstrong  路  3Comments

hramos picture hramos  路  3Comments

ticky picture ticky  路  3Comments

ianp picture ianp  路  3Comments