-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
assert: add warning about assert.doesNotReject
#19462
Conversation
The usefulness of `assert.doesNotReject` is very limited and this warns against the usage.
Please note: Using `assert.doesNotReject()` is actually not useful because there | ||
is little benefit by catching a rejection and then rejecting it again. Instead, | ||
consider adding a comment next to the specific code path that should not reject | ||
and keep error messages as expressive as possible. |
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.
Suggestions: Get rid of Please note:
and keep the first sentence concise:
There is little benefit to using `assert.doesNotReject()`. Instead, consider adding a comment...
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 specific case I would rather keep the Please note
as I really want users to read this. That is also why it is placed prominently. And the text is currently similar to the one used in doesNotThrow
, so I thought I just keep them aligned.
|
@apapirovski I am not certain what the benefit of catching the rejection and rejecting it again is. Can you please elaborate? Your example is going to reject the same error that it caught without modifying it. |
@BridgeAR B'ah. I forgot it was all handled async anyway. I stopped following the development of that feature at some point. (In my mind we were throwing on nextTick.) |
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.
LGTM
Landed in 5d6d1fe |
The usefulness of `assert.doesNotReject` is very limited and this warns against the usage. PR-URL: nodejs#19462 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
Should land in v9.x only if #18023 makes it. |
The usefulness of `assert.doesNotReject` is very limited and this warns against the usage. PR-URL: nodejs#19462 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
The usefulness of
assert.doesNotReject
is very limited and thiswarns against the usage.
This keeps it in line with
assert.doesNotThrow
.Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes