Skip to content

Commit

Permalink
console: document the behavior of console.assert()
Browse files Browse the repository at this point in the history
Add a description and an example of console.assert() call with
no arguments. If called like this, the method should output:
"Assertion failed".

Fixes: #34500
Refs: https://nodejs.org/dist/latest-v14.x/docs/api/console.html#console_console_assert_value_message
Refs: https://console.spec.whatwg.org/#assert

PR-URL: #34501
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
  • Loading branch information
iandrc authored and codebytere committed Aug 5, 2020
1 parent f46649b commit 465968c
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions doc/api/console.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ changes:
* `...message` {any} All arguments besides `value` are used as error message.

A simple assertion test that verifies whether `value` is truthy. If it is not,
or `value` is not passed,
`Assertion failed` is logged. If provided, the error `message` is formatted
using [`util.format()`][] by passing along all message arguments. The output is
used as the error message.
Expand All @@ -160,6 +161,8 @@ console.assert(true, 'does nothing');
// OK
console.assert(false, 'Whoops %s work', 'didn\'t');
// Assertion failed: Whoops didn't work
console.assert();
// Assertion failed
```

Calling `console.assert()` with a falsy assertion will only cause the `message`
Expand Down

0 comments on commit 465968c

Please sign in to comment.