Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toThrowErrorMatchingSnapshot does not work with promises #4946

Closed
SimenB opened this issue Nov 24, 2017 · 3 comments · Fixed by #4962
Closed

toThrowErrorMatchingSnapshot does not work with promises #4946

SimenB opened this issue Nov 24, 2017 · 3 comments · Fixed by #4962

Comments

@SimenB
Copy link
Member

SimenB commented Nov 24, 2017

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

@SimenB
Copy link
Member Author

SimenB commented Nov 24, 2017

@lsentkiewicz would you be interested on working on this, similar to #4884? 🙂

@manu-st
Copy link

manu-st commented Oct 28, 2019

I'm using jest v24.7.1 and I'm still having the original issue. Was it really fixed?

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants