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

assert: add warning about assert.doesNotReject #19462

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions doc/api/assert.md
Expand Up @@ -321,10 +321,16 @@ added: REPLACEME
* `message` {any}

Awaits for the promise returned by function `block` to complete and not be
rejected. See [`assert.rejects()`][] for more details.
rejected.

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

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

Copy link
Member Author

@BridgeAR BridgeAR Mar 20, 2018

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.


When `assert.doesNotReject()` is called, it will immediately call the `block`
function, and awaits for completion.
function, and awaits for completion. See [`assert.rejects()`][] for more
details.

Besides the async nature to await the completion behaves identically to
[`assert.doesNotThrow()`][].
Expand Down