Jest: Expect rejects async/await documentation example fails

Created on 13 Dec 2017  ·  3Comments  ·  Source: facebook/jest

Attempting to follow this documentation:

Alternatively, you can use async/await in combination with .rejects.
test('rejects to octopus', async () => {
  await expect(Promise.reject(new Error('octopus'))).rejects.toThrow('octopus');
});

I get the error:

$ jest
 FAIL  .\index.test.js
  × async error handling from docs (5ms)

  ● async error handling from docs

    expect(function).toThrow(string)

    Received value must be a function, but instead "object" was found

Steps to reproduce:

  1. mkdir test
  2. yarn add jest
  3. touch index.test.js
  4. paste above example from documentation
    5) run jest

Environment (most likely of little relevance here):
yarn 1.3.2
node v8.5.0
windows 7

Most helpful comment

Correct, see #4884, #4945 etc

All 3 comments

This will be fixed in Jest 22. You can try jest@test to get the latest beta where this issue was fixed (correct me if I'm wrong @SimenB).

Correct, see #4884, #4945 etc

homer simpson doh

Was this page helpful?
0 / 5 - 0 ratings