Make rejects and resolves synchronously validate its argument#5364
Make rejects and resolves synchronously validate its argument#5364cpojer merged 9 commits intojestjs:masterfrom
rejects and resolves synchronously validate its argument#5364Conversation
|
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! |
|
@SimenB Please let me know if I missed something 😇 |
Codecov Report
@@ Coverage Diff @@
## master #5364 +/- ##
=======================================
Coverage 61.32% 61.32%
=======================================
Files 205 205
Lines 6925 6925
Branches 3 4 +1
=======================================
Hits 4247 4247
Misses 2677 2677
Partials 1 1Continue to review full report at Codecov.
|
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
SimenB
left a comment
There was a problem hiding this comment.
Please update the changelog as well
| } catch (e) { | ||
| return makeThrowingMatcher(matcher, isNot, e).apply(null, args); | ||
| } | ||
| return (async () => { |
There was a problem hiding this comment.
you can do
return result
.catch(e => makeThrowingMatcher(matcher, isNot, e).apply(null, args))
.then(() => Promise.reject(
// new JestAssertionError(...
));And drop the async
| ); | ||
| return Promise.reject(err); | ||
| }) | ||
| .catch(e => makeThrowingMatcher(matcher, isNot, e).apply(null, args)); |
There was a problem hiding this comment.
Wait no, that won't work either. You have to use .then(resolvedHandler, rejectedHandler) to avoid handling the rejection here.
So just move your catch into the second argument of the then.
There was a problem hiding this comment.
https://repl.it/repls/RevolvingEvergreenBlackbuck
Is there any difference between A and B, besides syntax preference? Both a and b pass the test cases.
There was a problem hiding this comment.
In this case, yes. since we expect it to fail we need to have our catch first so we can resolve the promise with it. But if it does not reject we need to reject it ourselves.
If we add a then after the catch, it's not called. If we add our catch onto a then, we locally catch the rejection we want to bubble up
SimenB
left a comment
There was a problem hiding this comment.
Can you add the same for makeResolveMatcher?
|
OK, I'll add the same for |
makeRejectMatcher synchronizable (#5361)rejects and resolves synchronizable (#5361)
|
@incleaf can you run Also, please fix the conflict. |
|
@SimenB Just updated the snapshot and fixed the conflict. |
rejects and resolves synchronizable (#5361)rejects and resolves synchronous (#5361)
rejects and resolves synchronous (#5361)rejects and resolves synchronous
|
Yay, ci. Some weird permission stuff, but your last commit is green and my change was just to the changelog |
|
@SimenB Thank you for the review. It helped me a lot 😀 |
rejects and resolves synchronousrejects and resolves synchronously validate its argument
|
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
Fix #5361
Test plan
Pass non-promise values into reject matchers synchronously