Skip to content

Commit 01abed1

Browse files
BridgeARtargos
authored andcommitted
doc: update assert documentation
This adds concrete expected types to the assert documentation. It also fixes a `changes` entry and improves some minor comments. PR-URL: #20486 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
1 parent a5ee31b commit 01abed1

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

doc/api/assert.md

+25-25
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ assert.deepEqual(/a/gi, new Date());
154154
<!-- YAML
155155
added: v0.5.9
156156
-->
157-
* `value` {any}
158-
* `message` {any}
157+
* `value` {any} The input that is checked for being truthy.
158+
* `message` {string|Error}
159159

160160
An alias of [`assert.ok()`][].
161161

@@ -181,7 +181,7 @@ changes:
181181
-->
182182
* `actual` {any}
183183
* `expected` {any}
184-
* `message` {any}
184+
* `message` {string|Error}
185185

186186
**Strict mode**
187187

@@ -235,18 +235,18 @@ const obj3 = {
235235
const obj4 = Object.create(obj1);
236236

237237
assert.deepEqual(obj1, obj1);
238-
// OK, object is equal to itself
238+
// OK
239239

240+
// Values of b are different:
240241
assert.deepEqual(obj1, obj2);
241242
// AssertionError: { a: { b: 1 } } deepEqual { a: { b: 2 } }
242-
// values of b are different
243243

244244
assert.deepEqual(obj1, obj3);
245-
// OK, objects are equal
245+
// OK
246246

247+
// Prototypes are ignored:
247248
assert.deepEqual(obj1, obj4);
248249
// AssertionError: { a: { b: 1 } } deepEqual {}
249-
// Prototypes are ignored
250250
```
251251

252252
If the values are not equal, an `AssertionError` is thrown with a `message`
@@ -285,7 +285,7 @@ changes:
285285
-->
286286
* `actual` {any}
287287
* `expected` {any}
288-
* `message` {any}
288+
* `message` {string|Error}
289289

290290
Tests for deep equality between the `actual` and `expected` parameters.
291291
"Deep" equality means that the enumerable "own" properties of child objects
@@ -406,7 +406,7 @@ added: v10.0.0
406406
-->
407407
* `block` {Function|Promise}
408408
* `error` {RegExp|Function}
409-
* `message` {any}
409+
* `message` {string|Error}
410410

411411
Awaits the `block` promise or, if `block` is a function, immediately calls the
412412
function and awaits the returned promise to complete. It will then check that
@@ -460,7 +460,7 @@ changes:
460460
-->
461461
* `block` {Function}
462462
* `error` {RegExp|Function}
463-
* `message` {any}
463+
* `message` {string|Error}
464464

465465
Asserts that the function `block` does not throw an error.
466466

@@ -528,7 +528,7 @@ added: v0.1.21
528528
-->
529529
* `actual` {any}
530530
* `expected` {any}
531-
* `message` {any}
531+
* `message` {string|Error}
532532

533533
**Strict mode**
534534

@@ -565,7 +565,7 @@ parameter is an instance of an [`Error`][] then it will be thrown instead of the
565565
<!-- YAML
566566
added: v0.1.21
567567
-->
568-
* `message` {any} **Default:** `'Failed'`
568+
* `message` {string|Error} **Default:** `'Failed'`
569569

570570
Throws an `AssertionError` with the provided error message or a default error
571571
message. If the `message` parameter is an instance of an [`Error`][] then it
@@ -598,7 +598,7 @@ changes:
598598
-->
599599
* `actual` {any}
600600
* `expected` {any}
601-
* `message` {any}
601+
* `message` {string|Error}
602602
* `operator` {string} **Default:** `'!='`
603603
* `stackStartFunction` {Function} **Default:** `assert.fail`
604604

@@ -659,8 +659,8 @@ changes:
659659
an `AssertionError` that contains the full stack trace.
660660
- version: v10.0.0
661661
pr-url: https://github.com/nodejs/node/pull/18247
662-
description: Value may now only be `undefined` or `null`. Before any truthy
663-
input was accepted.
662+
description: Value may now only be `undefined` or `null`. Before all falsy
663+
values were handled the same as `null` and did not throw.
664664
-->
665665
* `value` {any}
666666

@@ -717,7 +717,7 @@ changes:
717717
-->
718718
* `actual` {any}
719719
* `expected` {any}
720-
* `message` {any}
720+
* `message` {string|Error}
721721

722722
**Strict mode**
723723

@@ -753,13 +753,13 @@ assert.notDeepEqual(obj1, obj1);
753753
// AssertionError: { a: { b: 1 } } notDeepEqual { a: { b: 1 } }
754754

755755
assert.notDeepEqual(obj1, obj2);
756-
// OK: obj1 and obj2 are not deeply equal
756+
// OK
757757

758758
assert.notDeepEqual(obj1, obj3);
759759
// AssertionError: { a: { b: 1 } } notDeepEqual { a: { b: 1 } }
760760

761761
assert.notDeepEqual(obj1, obj4);
762-
// OK: obj1 and obj4 are not deeply equal
762+
// OK
763763
```
764764

765765
If the values are deeply equal, an `AssertionError` is thrown with a `message`
@@ -798,7 +798,7 @@ changes:
798798
-->
799799
* `actual` {any}
800800
* `expected` {any}
801-
* `message` {any}
801+
* `message` {string|Error}
802802

803803
Tests for deep strict inequality. Opposite of [`assert.deepStrictEqual()`][].
804804

@@ -821,7 +821,7 @@ added: v0.1.21
821821
-->
822822
* `actual` {any}
823823
* `expected` {any}
824-
* `message` {any}
824+
* `message` {string|Error}
825825

826826
**Strict mode**
827827

@@ -863,7 +863,7 @@ changes:
863863
-->
864864
* `actual` {any}
865865
* `expected` {any}
866-
* `message` {any}
866+
* `message` {string|Error}
867867

868868
Tests strict inequality between the `actual` and `expected` parameters as
869869
determined by the [SameValue Comparison][].
@@ -897,7 +897,7 @@ changes:
897897
error message.
898898
-->
899899
* `value` {any}
900-
* `message` {any}
900+
* `message` {string|Error}
901901

902902
Tests if `value` is truthy. It is equivalent to
903903
`assert.equal(!!value, true, message)`.
@@ -960,7 +960,7 @@ added: v10.0.0
960960
-->
961961
* `block` {Function|Promise}
962962
* `error` {RegExp|Function|Object|Error}
963-
* `message` {any}
963+
* `message` {string|Error}
964964

965965
Awaits the `block` promise or, if `block` is a function, immediately calls the
966966
function and awaits the returned promise to complete. It will then check that
@@ -1022,7 +1022,7 @@ changes:
10221022
-->
10231023
* `actual` {any}
10241024
* `expected` {any}
1025-
* `message` {any}
1025+
* `message` {string|Error}
10261026

10271027
Tests strict equality between the `actual` and `expected` parameters as
10281028
determined by the [SameValue Comparison][].
@@ -1065,7 +1065,7 @@ changes:
10651065
-->
10661066
* `block` {Function}
10671067
* `error` {RegExp|Function|Object|Error}
1068-
* `message` {any}
1068+
* `message` {string|Error}
10691069

10701070
Expects the function `block` to throw an error.
10711071

0 commit comments

Comments
 (0)