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

expect(…).rejects.toMatch(…) should handle an Error object #3699

Closed
hubgit opened this issue May 31, 2017 · 4 comments
Closed

expect(…).rejects.toMatch(…) should handle an Error object #3699

hubgit opened this issue May 31, 2017 · 4 comments

Comments

@hubgit
Copy link

hubgit commented May 31, 2017

The current documentation contains the following example:

test('fetchData() rejects to be error', async () => {
  const drinkOctopus = new Promise(() => {
      throw new DisgustingFlavorError('yuck, octopus flavor');
  });

  await expect(drinkOctopus).rejects.toMatch('octopus');
});

Simplified slightly, this would be expected to pass:

  it('throws an error', async () => {
    const drinkOctopus = new Promise(() => {
      throw new Error('yuck, octopus flavor');
    });

    await expect(drinkOctopus).rejects.toMatch('octopus');
  });

Running this test in Jest v20.0.4 (node v8.0.0) produces an error:

Failed: expect(string)[.not].toMatch(expected)

string value must be a string.
Received:
  object: [Error: yuck, octopus flavor]

The Promise is rejecting with an Error rather than a string, as it should, but Jest isn't handling this as expected.

@julienw
Copy link

julienw commented May 31, 2017

We also discuss about this in #3601 so it might be a dupe.

@rogeliog
Copy link
Contributor

rogeliog commented Jun 8, 2017

Yeah it seems like a dupe... Closing in favor of #3601

@rogeliog rogeliog closed this as completed Jun 8, 2017
@franciscop
Copy link

I wouldn't close this; while the solution is being discussed on #3601, I think a quick documentation change is needed ATM so this issue seems fit for that as it looks like not even a solution is proposed yet in that issue.

I think developers using the documentation should not be expected to find an issue in Github that tells them that the docs are wrong. So I propose to reopen this issue as: "Update the documentation to reflect current status of things".

@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 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants