Skip to content

Expect rejects async/await documentation example fails #5076

Description

@brysgo

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
  1. run jest

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions