-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Updated expect API docs with .resolves and .rejects #3172
Conversation
Some of our docs note that features became available in Jest 19, would you mind adding the same note for these with "Jest 20"? :) |
No problem, I updated the API docs accordingly:) |
Codecov Report
@@ Coverage Diff @@
## master #3172 +/- ##
==========================================
+ Coverage 61.72% 69.47% +7.75%
==========================================
Files 174 157 -17
Lines 6555 5550 -1005
Branches 3 3
==========================================
- Hits 4046 3856 -190
+ Misses 2508 1693 -815
Partials 1 1
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have some very minor nits, then we can merge this. Thanks for adding this to the docs!
docs/ExpectAPI.md
Outdated
|
||
```js | ||
test('fetchData() resolves and is peanut butter', () => { | ||
//make sure to add a return statement |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a single space after //
docs/ExpectAPI.md
Outdated
|
||
```js | ||
test('fetchData() rejects to be error', () => { | ||
//make sure to add a return statement |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a single space after //
Errors can be handled in the standard JavaScript way: Either using `.catch()` | ||
directly on a Promise or through `try-catch` when using async/await. Note that | ||
if a Promise throws and the error is not handled, the test will fail. `expect.assertion(1)` makes sure that expectation was checked once. In this example it will fail if promise was resolved without throwing. | ||
Errors can be handled using the keyword `rejects` in your expect statement. This will verify that the promise rejects and perform an assertion on the resulting error. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like that the new API allows us to rewrite this entire paragraph! People just need to use rejects
now. Good job!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it's really simple to do these checks now, I am glad that this is supported out of the box now!
Thanks for taking a look @hramos! I have updated the PR:) |
Strange, the CI is failing from the tiny change I made. Is this an issue with jest? |
These are markdown-only changes, I don't think the Travis failures are related. |
@@ -48,15 +48,13 @@ If `done()` is never called, the test will fail, which is what you want to happe | |||
|
|||
### Promises |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This section should really mention expect.assertions. cc @hramos, mind adding a line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @cpojer. Could you elaborate a bit more what you want written here? In the TutorialAsync.md
file we removed a section that contained expect.assertions()
, would you like to add this back into the documentation so that people who use older versions of jest can still reference the docs for async problems?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created an issue for this (and some other issues I noticed) see #3273
* Updated expect API docs with .resolves and .rejects * Fixed linter errors in the docs. * added API availability status * minor styling issue fix
* Updated expect API docs with .resolves and .rejects * Fixed linter errors in the docs. * added API availability status * minor styling issue fix
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. |
Follow-up from PR #3068. This PR updates the docs to incorporate the new
.resolves
and.rejects
keywords in the expect API.