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

confused .rejects example in Jest document #9143

Closed
Jongmun-Park opened this issue Nov 6, 2019 · 4 comments
Closed

confused .rejects example in Jest document #9143

Jongmun-Park opened this issue Nov 6, 2019 · 4 comments

Comments

@Jongmun-Park
Copy link
Contributor

Jongmun-Park commented Nov 6, 2019

Hi.
I learned about .rejects function in Jest document example
https://jestjs.io/docs/en/tutorial-async#rejects

here is the example.

// Testing for async errors using `.rejects`.
it('tests error with rejects', () => {
  expect.assertions(1);
  return expect(user.getUserName(3)).rejects.toEqual({
    error: 'User with 3 not found.',
  });
});

// Or using async/await with `.rejects`.
it('tests error with async/await and rejects', async () => {
  expect.assertions(1);
  await expect(user.getUserName(3)).rejects.toEqual({
    error: 'User with 3 not found.',
  });
});

The example used expect.assertions(1);
but, i searched that it is necessary to use assertions with .rejects
then i found this issue 'removed useless expect.assertions'
#7131

so i suggest how about removing expect.assertions(1); code in the example.
becauese i was not sure whether I should used assertions.

thank u.

@joelbarbosa
Copy link

Yes you are right, that code expect.assertions(1); is usuless that. As the rejects will always to occur here. I think its a good first commit.

@github-actions
Copy link

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Feb 17, 2023
@github-actions
Copy link

This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Mar 19, 2023
@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 Apr 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants