@@ -218,8 +218,9 @@ are also recursively evaluated by the following rules.
218
218
* [ ` Symbol ` ] [ ] properties are not compared.
219
219
* [ ` WeakMap ` ] [ ] and [ ` WeakSet ` ] [ ] comparison does not rely on their values.
220
220
221
- The following example does not throw an ` AssertionError ` because the primitives
222
- are considered equal by the [ Abstract Equality Comparison] [ ] ( ` == ` ).
221
+ The following example does not throw an [ ` AssertionError ` ] [ ] because the
222
+ primitives are considered equal by the [ Abstract Equality Comparison] [ ]
223
+ ( ` == ` ).
223
224
224
225
``` js
225
226
// WARNING: This does not throw an AssertionError!
@@ -264,11 +265,11 @@ assert.deepEqual(obj1, obj4);
264
265
// AssertionError: { a: { b: 1 } } deepEqual {}
265
266
```
266
267
267
- If the values are not equal, an ` AssertionError ` is thrown with a ` message `
268
+ If the values are not equal, an [ ` AssertionError ` ] [ ] is thrown with a ` message `
268
269
property set equal to the value of the ` message ` parameter. If the ` message `
269
270
parameter is undefined, a default error message is assigned. If the ` message `
270
271
parameter is an instance of an [ ` Error ` ] [ ] then it will be thrown instead of the
271
- ` AssertionError ` .
272
+ [ ` AssertionError ` ] [ ] .
272
273
273
274
## ` assert.deepStrictEqual(actual, expected[, message]) `
274
275
<!-- YAML
@@ -418,7 +419,7 @@ assert.deepStrictEqual(weakMap1, weakMap3);
418
419
// }
419
420
```
420
421
421
- If the values are not equal, an ` AssertionError ` is thrown with a ` message `
422
+ If the values are not equal, an [ ` AssertionError ` ] [ ] is thrown with a ` message `
422
423
property set equal to the value of the ` message ` parameter. If the ` message `
423
424
parameter is undefined, a default error message is assigned. If the ` message `
424
425
parameter is an instance of an [ ` Error ` ] [ ] then it will be thrown instead of the
@@ -501,9 +502,9 @@ When `assert.doesNotThrow()` is called, it will immediately call the `fn`
501
502
function.
502
503
503
504
If an error is thrown and it is the same type as that specified by the ` error `
504
- parameter, then an ` AssertionError ` is thrown. If the error is of a different
505
- type, or if the ` error ` parameter is undefined, the error is propagated back
506
- to the caller.
505
+ parameter, then an [ ` AssertionError ` ] [ ] is thrown. If the error is of a
506
+ different type, or if the ` error ` parameter is undefined, the error is
507
+ propagated back to the caller.
507
508
508
509
If specified, ` error ` can be a [ ` Class ` ] [ ] , [ ` RegExp ` ] [ ] or a validation
509
510
function. See [ ` assert.throws() ` ] [ ] for more details.
@@ -521,7 +522,7 @@ assert.doesNotThrow(
521
522
);
522
523
```
523
524
524
- However, the following will result in an ` AssertionError ` with the message
525
+ However, the following will result in an [ ` AssertionError ` ] [ ] with the message
525
526
'Got unwanted exception...':
526
527
527
528
<!-- eslint-disable no-restricted-syntax -->
@@ -534,8 +535,8 @@ assert.doesNotThrow(
534
535
);
535
536
```
536
537
537
- If an ` AssertionError ` is thrown and a value is provided for the ` message `
538
- parameter, the value of ` message ` will be appended to the ` AssertionError `
538
+ If an [ ` AssertionError ` ] [ ] is thrown and a value is provided for the ` message `
539
+ parameter, the value of ` message ` will be appended to the [ ` AssertionError ` ] [ ]
539
540
message:
540
541
541
542
<!-- eslint-disable no-restricted-syntax -->
@@ -584,7 +585,7 @@ assert.equal({ a: { b: 1 } }, { a: { b: 1 } });
584
585
// AssertionError: { a: { b: 1 } } == { a: { b: 1 } }
585
586
```
586
587
587
- If the values are not equal, an ` AssertionError ` is thrown with a ` message `
588
+ If the values are not equal, an [ ` AssertionError ` ] [ ] is thrown with a ` message `
588
589
property set equal to the value of the ` message ` parameter. If the ` message `
589
590
parameter is undefined, a default error message is assigned. If the ` message `
590
591
parameter is an instance of an [ ` Error ` ] [ ] then it will be thrown instead of the
@@ -597,9 +598,9 @@ added: v0.1.21
597
598
598
599
* ` message ` {string|Error} ** Default:** ` 'Failed' `
599
600
600
- Throws an ` AssertionError ` with the provided error message or a default error
601
- message. If the ` message ` parameter is an instance of an [ ` Error ` ] [ ] then it
602
- will be thrown instead of the ` AssertionError ` .
601
+ Throws an [ ` AssertionError ` ] [ ] with the provided error message or a default
602
+ error message. If the ` message ` parameter is an instance of an [ ` Error ` ] [ ] then
603
+ it will be thrown instead of the [ ` AssertionError ` ] [ ] .
603
604
604
605
``` js
605
606
const assert = require (' assert' ).strict ;
@@ -687,7 +688,7 @@ changes:
687
688
- version: v10.0.0
688
689
pr-url: https://github.com/nodejs/node/pull/18247
689
690
description: Instead of throwing the original error it is now wrapped into
690
- an `AssertionError` that contains the full stack trace.
691
+ an [ `AssertionError`][] that contains the full stack trace.
691
692
- version: v10.0.0
692
693
pr-url: https://github.com/nodejs/node/pull/18247
693
694
description: Value may now only be `undefined` or `null`. Before all falsy
@@ -795,11 +796,11 @@ assert.notDeepEqual(obj1, obj4);
795
796
// OK
796
797
```
797
798
798
- If the values are deeply equal, an ` AssertionError ` is thrown with a ` message `
799
- property set equal to the value of the ` message ` parameter. If the ` message `
800
- parameter is undefined, a default error message is assigned. If the ` message `
801
- parameter is an instance of an [ ` Error ` ] [ ] then it will be thrown instead of the
802
- ` AssertionError ` .
799
+ If the values are deeply equal, an [ ` AssertionError ` ] [ ] is thrown with a
800
+ ` message ` property set equal to the value of the ` message ` parameter. If the
801
+ ` message ` parameter is undefined, a default error message is assigned. If the
802
+ ` message ` parameter is an instance of an [ ` Error ` ] [ ] then it will be thrown
803
+ instead of the ` AssertionError ` .
803
804
804
805
## ` assert.notDeepStrictEqual(actual, expected[, message]) `
805
806
<!-- YAML
@@ -843,11 +844,11 @@ assert.notDeepStrictEqual({ a: 1 }, { a: '1' });
843
844
// OK
844
845
```
845
846
846
- If the values are deeply and strictly equal, an ` AssertionError ` is thrown with
847
- a ` message ` property set equal to the value of the ` message ` parameter. If the
848
- ` message ` parameter is undefined, a default error message is assigned. If the
849
- ` message ` parameter is an instance of an [ ` Error ` ] [ ] then it will be thrown
850
- instead of the ` AssertionError ` .
847
+ If the values are deeply and strictly equal, an [ ` AssertionError ` ] [ ] is thrown
848
+ with a ` message ` property set equal to the value of the ` message ` parameter. If
849
+ the ` message ` parameter is undefined, a default error message is assigned. If
850
+ the ` message ` parameter is an instance of an [ ` Error ` ] [ ] then it will be thrown
851
+ instead of the [ ` AssertionError ` ] [ ] .
851
852
852
853
## ` assert.notEqual(actual, expected[, message]) `
853
854
<!-- YAML
@@ -882,10 +883,10 @@ assert.notEqual(1, '1');
882
883
// AssertionError: 1 != '1'
883
884
```
884
885
885
- If the values are equal, an ` AssertionError ` is thrown with a ` message ` property
886
- set equal to the value of the ` message ` parameter. If the ` message ` parameter is
887
- undefined, a default error message is assigned. If the ` message ` parameter is an
888
- instance of an [ ` Error ` ] [ ] then it will be thrown instead of the
886
+ If the values are equal, an [ ` AssertionError ` ] [ ] is thrown with a ` message `
887
+ property set equal to the value of the ` message ` parameter. If the ` message `
888
+ parameter is undefined, a default error message is assigned. If the ` message `
889
+ parameter is an instance of an [ ` Error ` ] [ ] then it will be thrown instead of the
889
890
` AssertionError ` .
890
891
891
892
## ` assert.notStrictEqual(actual, expected[, message]) `
@@ -919,11 +920,11 @@ assert.notStrictEqual(1, '1');
919
920
// OK
920
921
```
921
922
922
- If the values are strictly equal, an ` AssertionError ` is thrown with a ` message `
923
- property set equal to the value of the ` message ` parameter. If the ` message `
924
- parameter is undefined, a default error message is assigned. If the ` message `
925
- parameter is an instance of an [ ` Error ` ] [ ] then it will be thrown instead of the
926
- ` AssertionError ` .
923
+ If the values are strictly equal, an [ ` AssertionError ` ] [ ] is thrown with a
924
+ ` message ` property set equal to the value of the ` message ` parameter. If the
925
+ ` message ` parameter is undefined, a default error message is assigned. If the
926
+ ` message ` parameter is an instance of an [ ` Error ` ] [ ] then it will be thrown
927
+ instead of the ` AssertionError ` .
927
928
928
929
## ` assert.ok(value[, message]) `
929
930
<!-- YAML
@@ -941,7 +942,7 @@ changes:
941
942
Tests if ` value ` is truthy. It is equivalent to
942
943
` assert.equal(!!value, true, message) ` .
943
944
944
- If ` value ` is not truthy, an ` AssertionError ` is thrown with a ` message `
945
+ If ` value ` is not truthy, an [ ` AssertionError ` ] [ ] is thrown with a ` message `
945
946
property set equal to the value of the ` message ` parameter. If the ` message `
946
947
parameter is ` undefined ` , a default error message is assigned. If the ` message `
947
948
parameter is an instance of an [ ` Error ` ] [ ] then it will be thrown instead of the
@@ -1020,8 +1021,8 @@ an object where each property will be tested for, or an instance of error where
1020
1021
each property will be tested for including the non-enumerable ` message ` and
1021
1022
` name ` properties.
1022
1023
1023
- If specified, ` message ` will be the message provided by the ` AssertionError ` if
1024
- the ` asyncFn ` fails to reject.
1024
+ If specified, ` message ` will be the message provided by the [ ` AssertionError ` ] [ ]
1025
+ if the ` asyncFn ` fails to reject.
1025
1026
1026
1027
``` js
1027
1028
(async () => {
@@ -1096,11 +1097,11 @@ assert.strictEqual(1, '1', new TypeError('Inputs are not identical'));
1096
1097
// TypeError: Inputs are not identical
1097
1098
```
1098
1099
1099
- If the values are not strictly equal, an ` AssertionError ` is thrown with a
1100
+ If the values are not strictly equal, an [ ` AssertionError ` ] [ ] is thrown with a
1100
1101
` message ` property set equal to the value of the ` message ` parameter. If the
1101
1102
` message ` parameter is undefined, a default error message is assigned. If the
1102
1103
` message ` parameter is an instance of an [ ` Error ` ] [ ] then it will be thrown
1103
- instead of the ` AssertionError ` .
1104
+ instead of the [ ` AssertionError ` ] [ ] .
1104
1105
1105
1106
## ` assert.throws(fn[, error][, message]) `
1106
1107
<!-- YAML
@@ -1231,6 +1232,9 @@ assert.throws(
1231
1232
1232
1233
Custom error validation:
1233
1234
1235
+ The function must return ` true ` to indicate all internal validations passed.
1236
+ It will otherwise fail with an [ ` AssertionError ` ] [ ] .
1237
+
1234
1238
``` js
1235
1239
assert .throws (
1236
1240
() => {
@@ -1295,6 +1299,7 @@ assert.throws(throwingFirst, /Second$/);
1295
1299
Due to the confusing error-prone notation, avoid a string as the second
1296
1300
argument.
1297
1301
1302
+ [ `AssertionError` ] : #assert_class_assert_assertionerror
1298
1303
[ `Class` ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes
1299
1304
[ `ERR_INVALID_RETURN_VALUE` ] : errors.html#errors_err_invalid_return_value
1300
1305
[ `Error.captureStackTrace` ] : errors.html#errors_error_capturestacktrace_targetobject_constructoropt
0 commit comments