-
-
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
Make rejects
and resolves
synchronously validate its argument
#5364
Conversation
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 [email protected]. 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 1 Continue 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! |
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.
Please update the changelog as well
packages/expect/src/index.js
Outdated
} catch (e) { | ||
return makeThrowingMatcher(matcher, isNot, e).apply(null, args); | ||
} | ||
return (async () => { |
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.
you can do
return result
.catch(e => makeThrowingMatcher(matcher, isNot, e).apply(null, args))
.then(() => Promise.reject(
// new JestAssertionError(...
));
And drop the async
packages/expect/src/index.js
Outdated
); | ||
return Promise.reject(err); | ||
}) | ||
.catch(e => makeThrowingMatcher(matcher, isNot, e).apply(null, args)); |
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 catch
has to be first
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
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.
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
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.
Thanks!
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