Jest: Jest marks a test as "Passed" when an assertion fails on a `.resolves`

Created on 1 Dec 2017  路  6Comments  路  Source: facebook/jest

Do you want to request a _feature_ or report a _bug_?

A bug.

What is the current behavior?

The following assertion fails:

expect(Promise.resolve('Expected value')).resolves.toBe('Not the expected value');

It throws an error, but nevertheless, Jest marks the test as Passed. See this repl.it:

https://repl.it/repls/ObedientNegativeGrison

What is the expected behavior?

Jest should mention that the test failed.

Please provide your exact Jest configuration and mention your Jest, node,
yarn/npm version and operating system.

$ yarn run jest --version
v21.2.1

$ node --version
v6.11.3

$ yarn --version
1.3.2

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.3 LTS
Release:        16.04
Codename:       xenial

Most helpful comment

You have to return (or await) the expect.

http://facebook.github.io/jest/docs/en/expect.html#resolves

All 6 comments

You have to return (or await) the expect.

http://facebook.github.io/jest/docs/en/expect.html#resolves

Oh really? Ugh, sorry for wasting your time - I thought that requirement had been removed with the addition of .resolves.

You still have to somehow tell jest to wait for it - it's still a promise 馃檪

Difference now is that you await the expect itself, and not the value within it

Hehe yeah it makes sense. Gives me some bad faith about all those tests I've already written without this measure :P I could submit a PR to emphasise this in the docs if you think that's a good idea?

Please do! All doc improvements are very welcome

@SimenB #4999 - almost at number 5000!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kentor picture kentor  路  3Comments

ticky picture ticky  路  3Comments

Secretmapper picture Secretmapper  路  3Comments

kgowru picture kgowru  路  3Comments

samzhang111 picture samzhang111  路  3Comments