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

Docs - Expect API - toThrow - Added a note about the type of value thrown #8772

Closed
wants to merge 2 commits into from

Conversation

SSTPIERRE2
Copy link

Summary

I and some others have ran into issues where one is testing some code they expect to throw, but the code doesn't specifically throw an instance of Error, the test will simply fail without explanation. This can be due to throwing anything other than new Error(...), where Jest will not recognize what the function has thrown. This addition to the docs merely clarifies that toThrow is specifically looking for an instance of Error.

Test plan

None, simple addition to the docs for clarification.

@facebook-github-bot
Copy link
Contributor

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@SSTPIERRE2
Copy link
Author

Looks like the jest-circus test failed, it doesn't appear related to the readme, but I could be wrong. Please advise, thanks!

@lh0x00
Copy link
Contributor

lh0x00 commented Aug 2, 2019

test-jest-circus is work incorrect sometimes 💃

@pedrottimark
Copy link
Contributor

@SSTPIERRE2 Thank you for contributing to Jest. To help interact on your contribution:

  1. Can you say which version?
  2. Can you give a few examples of confusing tests that motivate the sentence? The wording might need to become more specific for which type of expected argument in the assertion.

For example, toThrow assertion without argument works for values that are not instance of Error:

test('toThrow without expected value', () => {
  const received = () => {
    throw 13;
  };

  expect(received).toThrow();
  expect(received).not.toThrow();
});
expect(received).not.toThrow()

Thrown value: 13

This improvement in the report from #7621 in Jest 24.0.0 or later

P.S. Yes, ignore test-jest-circus failure on CI

When you edit Jest .md files, you can run locally yarn lint:md before you commit the change

@SimenB
Copy link
Member

SimenB commented Nov 9, 2019

Rebasing on master should fix CI, fwiw

@thymikee thymikee force-pushed the docs-update-expect-toThrow branch from 3215722 to 06dccdb Compare May 2, 2020 13:31
@thymikee thymikee force-pushed the docs-update-expect-toThrow branch from 06dccdb to 0bd48ca Compare May 2, 2020 13:32
@thymikee thymikee requested a review from pedrottimark May 2, 2020 13:35
@codecov-io
Copy link

Codecov Report

Merging #8772 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #8772   +/-   ##
=======================================
  Coverage   64.13%   64.13%           
=======================================
  Files         292      292           
  Lines       12452    12452           
  Branches     3072     3072           
=======================================
  Hits         7986     7986           
  Misses       3821     3821           
  Partials      645      645           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ea04be5...0bd48ca. Read the comment docs.

@SimenB
Copy link
Member

SimenB commented Feb 24, 2022

From #8772 (comment), I don't think the docs change is correct, so closing.

Feel free to open a new PR if I'm mistaken!

@SimenB SimenB closed this Feb 24, 2022
@github-actions
Copy link

This pull request 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 Mar 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants