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

Updated expect API docs with .resolves and .rejects #3172

Merged
merged 4 commits into from
Mar 21, 2017
Merged

Updated expect API docs with .resolves and .rejects #3172

merged 4 commits into from
Mar 21, 2017

Conversation

excitement-engineer
Copy link
Contributor

Follow-up from PR #3068. This PR updates the docs to incorporate the new .resolves and .rejects keywords in the expect API.

@cpojer cpojer requested a review from hramos March 19, 2017 01:24
@cpojer
Copy link
Member

cpojer commented Mar 19, 2017

Some of our docs note that features became available in Jest 19, would you mind adding the same note for these with "Jest 20"? :)

@excitement-engineer
Copy link
Contributor Author

No problem, I updated the API docs accordingly:)

@codecov-io
Copy link

Codecov Report

Merging #3172 into master will increase coverage by 7.75%.
The diff coverage is n/a.

@@            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
Impacted Files Coverage Δ
packages/pretty-format/src/plugins/ConvertAnsi.js 0% <0%> (-100%) ⬇️
packages/jest-cli/src/TestRunner.js 29.8% <0%> (-3.53%) ⬇️
packages/pretty-format/src/plugins/ReactElement.js 97.77% <0%> (-2.23%) ⬇️
packages/jest-cli/src/reporters/VerboseReporter.js 30% <0%> (-0.62%) ⬇️
packages/jest-jasmine2/src/jest-expect.js 0% <0%> (ø) ⬆️
packages/jest-jasmine2/src/index.js 0% <0%> (ø) ⬆️
packages/jest-cli/src/runJest.js 0% <0%> (ø) ⬆️
packages/jest-runtime/src/index.js 75% <0%> (ø) ⬆️
packages/jest-cli/src/jest.js 0% <0%> (ø) ⬆️
...ges/jest-haste-map/src/lib/getPlatformExtension.js 100% <0%> (ø) ⬆️
... and 23 more

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 a37ba1a...797af54. Read the comment docs.

Copy link
Contributor

@hramos hramos left a 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!


```js
test('fetchData() resolves and is peanut butter', () => {
//make sure to add a return statement
Copy link
Contributor

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 //


```js
test('fetchData() rejects to be error', () => {
//make sure to add a return statement
Copy link
Contributor

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.
Copy link
Contributor

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!

Copy link
Contributor Author

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!

@excitement-engineer
Copy link
Contributor Author

Thanks for taking a look @hramos! I have updated the PR:)

@excitement-engineer
Copy link
Contributor Author

Strange, the CI is failing from the tiny change I made. Is this an issue with jest?

@hramos
Copy link
Contributor

hramos commented Mar 21, 2017

These are markdown-only changes, I don't think the Travis failures are related.

@hramos hramos merged commit 74bb34d into jestjs:master Mar 21, 2017
@@ -48,15 +48,13 @@ If `done()` is never called, the test will fail, which is what you want to happe

### Promises
Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Contributor Author

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

skovhus pushed a commit to skovhus/jest that referenced this pull request Apr 29, 2017
* Updated expect API docs with .resolves and .rejects

* Fixed linter errors in the docs.

* added API availability status

* minor styling issue fix
tushardhole pushed a commit to tushardhole/jest that referenced this pull request Aug 21, 2017
* Updated expect API docs with .resolves and .rejects

* Fixed linter errors in the docs.

* added API availability status

* minor styling issue fix
@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 May 13, 2021
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.

5 participants