-
-
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
Update promise docs #3201
Update promise docs #3201
Conversation
0c991d6
to
ec62e18
Compare
ec62e18
to
f8224fb
Compare
@excitement-engineer and @cpojer, could you please look at this and give me some feedback? |
Codecov Report
@@ Coverage Diff @@
## master #3201 +/- ##
=======================================
Coverage 63.99% 63.99%
=======================================
Files 177 177
Lines 6574 6574
Branches 4 4
=======================================
Hits 4207 4207
Misses 2365 2365
Partials 2 2 Continue to review full report at Codecov.
|
docs/GlobalAPI.md
Outdated
}); | ||
``` | ||
|
||
Even though the call to `test` will return right away, the test doesn't complete until the promise resolves as well. |
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 think that these examples are really valuable for people using older versions of jest (i.e. Jest 19 and before) because these versions do not include the .resolves
yet. So perhaps we should consider keeping this.
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, let's keep this please.
await user.getUserName(2); | ||
} catch (object) { | ||
expect(object.error).toEqual('User with 2 not found.'); | ||
} |
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 would keep these code examples. They are really useful people using older versions of jest.
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.
Perhaps we can add the .rejects
and .resolves
examples next to the old examples and mention that these keywords may only be used in jest 20+
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.
Yep, let's keep both examples around. I think that is best.
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.
OK, I agree, I haven't taken into account the users of the previous versions.
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 went trough it again, and this change only reflects changes already in the docs in the async tutorial https://facebook.github.io/jest/docs/tutorial-async.html
Now the tutorial and sample code differ.
@robinpokorny thanks for helping improve the documentation. I agree with @excitement-engineer, let's keep the old examples around. We aren't deprecating the old way of testing for promises, we are only introducing a second way to test promises. We should also make sure to use |
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.
See comments.
@robinpokorny are you planning on addressing the feedback from my review? |
@cpojer, Yes, sorry. Will do it today or tomorrow. |
2af8089
to
969d1a7
Compare
I will update the ‘Testing Asynchronous Code’ article to include both options and recommends use of |
Yeah, let's add it to every async test to educate people about it :) Whether they'll use it in the end is not our problem then :D We did our best! |
Hey @robinpokorny, do you think you can give this another final pass? |
969d1a7
to
c6abeb2
Compare
5e5bc75
to
9694cf7
Compare
Uff, @cpojer, finally had the time for the rewrite. I added I also made sure that in both the async tutorial and async testing article, we show all four combinations:
|
Thanks @robinpokorny, this is great :) |
* Update docs on promises * Remove promises from `expect.assertions` and `test` * Keep docs for promise return * Update async docs * Update the async tutorial * Nicer headlines in Testing Async code * Update TestingAsyncCode.md * Update TutorialAsync.md
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. |
Summary
This pull request changes the documentation at several places regarding the recent async testing handling using
.resolves
and.rejects
..resolves
and.rejects
API docs.Remove old (non-resolves) promise assertions everywhere in docs.rejects
matcher in ‘Testing Asynchronous Code’.Related PR: #3172, #3068
Test plan
Changes in the docs.