Skip to content

toThrowErrorMatchingSnapshot does not work with promises #4946

Description

@SimenB

Do you want to request a feature or report a bug?
Feature

What is the current behavior?
One cannot use .rejects.toThrowErrorMatchingSnapshot() on a rejected promise. This means there's not the same parity between synchronous and asynchronus toThrow introduced in #4884.

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.

test('should support rejecting promises', async () => {
  expect(() => { throw new Error('octopus'); }).toThrow('octopus');
  expect(() => { throw new Error('octopus'); }).toThrowErrorMatchingSnapshot();
  await expect(Promise.reject(new Error('octopus'))).rejects.toThrow('octopus');
  await expect(Promise.reject(new Error('octopus'))).rejects.toThrowErrorMatchingSnapshot();
});

This test passes, but the snapshot is actually this:

exports[`should support rejecting promises 1`] = `"octopus"`;

exports[`should support rejecting promises 2`] = `"received is not a function"`;

What is the expected behavior?
Snapshot should be

exports[`should support rejecting promises 1`] = `"octopus"`;

exports[`should support rejecting promises 2`] = `"octopus"`;

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

Jest@c760ae869372950ecd05a1c79eb9b918abf70e82 (curren master), node 8.9.1, yarn 1.3.1, macOS

Metadata

Metadata

Assignees

No one assigned

    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