Skip to content

Commit eef1b5a

Browse files
committed
doc: make AssertionError a link
This makes sure that `AssertionError` links to the correct place in the assert documentation. PR-URL: #28263 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 8fd7184 commit eef1b5a

File tree

1 file changed

+43
-41
lines changed

1 file changed

+43
-41
lines changed

doc/api/assert.md

+43-41
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,9 @@ are also recursively evaluated by the following rules.
214214
* [`Symbol`][] properties are not compared.
215215
* [`WeakMap`][] and [`WeakSet`][] comparison does not rely on their values.
216216

217-
The following example does not throw an `AssertionError` because the primitives
218-
are considered equal by the [Abstract Equality Comparison][] ( `==` ).
217+
The following example does not throw an [`AssertionError`][] because the
218+
primitives are considered equal by the [Abstract Equality Comparison][]
219+
( `==` ).
219220

220221
```js
221222
// WARNING: This does not throw an AssertionError!
@@ -260,11 +261,11 @@ assert.deepEqual(obj1, obj4);
260261
// AssertionError: { a: { b: 1 } } deepEqual {}
261262
```
262263

263-
If the values are not equal, an `AssertionError` is thrown with a `message`
264+
If the values are not equal, an [`AssertionError`][] is thrown with a `message`
264265
property set equal to the value of the `message` parameter. If the `message`
265266
parameter is undefined, a default error message is assigned. If the `message`
266267
parameter is an instance of an [`Error`][] then it will be thrown instead of the
267-
`AssertionError`.
268+
[`AssertionError`][].
268269

269270
## assert.deepStrictEqual(actual, expected[, message])
270271
<!-- YAML
@@ -414,7 +415,7 @@ assert.deepStrictEqual(weakMap1, weakMap3);
414415
// }
415416
```
416417

417-
If the values are not equal, an `AssertionError` is thrown with a `message`
418+
If the values are not equal, an [`AssertionError`][] is thrown with a `message`
418419
property set equal to the value of the `message` parameter. If the `message`
419420
parameter is undefined, a default error message is assigned. If the `message`
420421
parameter is an instance of an [`Error`][] then it will be thrown instead of the
@@ -497,9 +498,9 @@ When `assert.doesNotThrow()` is called, it will immediately call the `fn`
497498
function.
498499

499500
If an error is thrown and it is the same type as that specified by the `error`
500-
parameter, then an `AssertionError` is thrown. If the error is of a different
501-
type, or if the `error` parameter is undefined, the error is propagated back
502-
to the caller.
501+
parameter, then an [`AssertionError`][] is thrown. If the error is of a
502+
different type, or if the `error` parameter is undefined, the error is
503+
propagated back to the caller.
503504

504505
If specified, `error` can be a [`Class`][], [`RegExp`][] or a validation
505506
function. See [`assert.throws()`][] for more details.
@@ -517,7 +518,7 @@ assert.doesNotThrow(
517518
);
518519
```
519520

520-
However, the following will result in an `AssertionError` with the message
521+
However, the following will result in an [`AssertionError`][] with the message
521522
'Got unwanted exception...':
522523

523524
<!-- eslint-disable no-restricted-syntax -->
@@ -530,8 +531,8 @@ assert.doesNotThrow(
530531
);
531532
```
532533

533-
If an `AssertionError` is thrown and a value is provided for the `message`
534-
parameter, the value of `message` will be appended to the `AssertionError`
534+
If an [`AssertionError`][] is thrown and a value is provided for the `message`
535+
parameter, the value of `message` will be appended to the [`AssertionError`][]
535536
message:
536537

537538
<!-- eslint-disable no-restricted-syntax -->
@@ -580,7 +581,7 @@ assert.equal({ a: { b: 1 } }, { a: { b: 1 } });
580581
// AssertionError: { a: { b: 1 } } == { a: { b: 1 } }
581582
```
582583

583-
If the values are not equal, an `AssertionError` is thrown with a `message`
584+
If the values are not equal, an [`AssertionError`][] is thrown with a `message`
584585
property set equal to the value of the `message` parameter. If the `message`
585586
parameter is undefined, a default error message is assigned. If the `message`
586587
parameter is an instance of an [`Error`][] then it will be thrown instead of the
@@ -593,9 +594,9 @@ added: v0.1.21
593594

594595
* `message` {string|Error} **Default:** `'Failed'`
595596

596-
Throws an `AssertionError` with the provided error message or a default error
597-
message. If the `message` parameter is an instance of an [`Error`][] then it
598-
will be thrown instead of the `AssertionError`.
597+
Throws an [`AssertionError`][] with the provided error message or a default
598+
error message. If the `message` parameter is an instance of an [`Error`][] then
599+
it will be thrown instead of the [`AssertionError`][].
599600

600601
```js
601602
const assert = require('assert').strict;
@@ -683,7 +684,7 @@ changes:
683684
- version: v10.0.0
684685
pr-url: https://github.com/nodejs/node/pull/18247
685686
description: Instead of throwing the original error it is now wrapped into
686-
an `AssertionError` that contains the full stack trace.
687+
an [`AssertionError`][] that contains the full stack trace.
687688
- version: v10.0.0
688689
pr-url: https://github.com/nodejs/node/pull/18247
689690
description: Value may now only be `undefined` or `null`. Before all falsy
@@ -791,11 +792,11 @@ assert.notDeepEqual(obj1, obj4);
791792
// OK
792793
```
793794

794-
If the values are deeply equal, an `AssertionError` is thrown with a `message`
795-
property set equal to the value of the `message` parameter. If the `message`
796-
parameter is undefined, a default error message is assigned. If the `message`
797-
parameter is an instance of an [`Error`][] then it will be thrown instead of the
798-
`AssertionError`.
795+
If the values are deeply equal, an [`AssertionError`][] is thrown with a
796+
`message` property set equal to the value of the `message` parameter. If the
797+
`message` parameter is undefined, a default error message is assigned. If the
798+
`message` parameter is an instance of an [`Error`][] then it will be thrown
799+
instead of the `AssertionError`.
799800

800801
## assert.notDeepStrictEqual(actual, expected[, message])
801802
<!-- YAML
@@ -839,11 +840,11 @@ assert.notDeepStrictEqual({ a: 1 }, { a: '1' });
839840
// OK
840841
```
841842

842-
If the values are deeply and strictly equal, an `AssertionError` is thrown with
843-
a `message` property set equal to the value of the `message` parameter. If the
844-
`message` parameter is undefined, a default error message is assigned. If the
845-
`message` parameter is an instance of an [`Error`][] then it will be thrown
846-
instead of the `AssertionError`.
843+
If the values are deeply and strictly equal, an [`AssertionError`][] is thrown
844+
with a `message` property set equal to the value of the `message` parameter. If
845+
the `message` parameter is undefined, a default error message is assigned. If
846+
the `message` parameter is an instance of an [`Error`][] then it will be thrown
847+
instead of the [`AssertionError`][].
847848

848849
## assert.notEqual(actual, expected[, message])
849850
<!-- YAML
@@ -878,10 +879,10 @@ assert.notEqual(1, '1');
878879
// AssertionError: 1 != '1'
879880
```
880881

881-
If the values are equal, an `AssertionError` is thrown with a `message` property
882-
set equal to the value of the `message` parameter. If the `message` parameter is
883-
undefined, a default error message is assigned. If the `message` parameter is an
884-
instance of an [`Error`][] then it will be thrown instead of the
882+
If the values are equal, an [`AssertionError`][] is thrown with a `message`
883+
property set equal to the value of the `message` parameter. If the `message`
884+
parameter is undefined, a default error message is assigned. If the `message`
885+
parameter is an instance of an [`Error`][] then it will be thrown instead of the
885886
`AssertionError`.
886887

887888
## assert.notStrictEqual(actual, expected[, message])
@@ -915,11 +916,11 @@ assert.notStrictEqual(1, '1');
915916
// OK
916917
```
917918

918-
If the values are strictly equal, an `AssertionError` is thrown with a `message`
919-
property set equal to the value of the `message` parameter. If the `message`
920-
parameter is undefined, a default error message is assigned. If the `message`
921-
parameter is an instance of an [`Error`][] then it will be thrown instead of the
922-
`AssertionError`.
919+
If the values are strictly equal, an [`AssertionError`][] is thrown with a
920+
`message` property set equal to the value of the `message` parameter. If the
921+
`message` parameter is undefined, a default error message is assigned. If the
922+
`message` parameter is an instance of an [`Error`][] then it will be thrown
923+
instead of the `AssertionError`.
923924

924925
## assert.ok(value[, message])
925926
<!-- YAML
@@ -937,7 +938,7 @@ changes:
937938
Tests if `value` is truthy. It is equivalent to
938939
`assert.equal(!!value, true, message)`.
939940

940-
If `value` is not truthy, an `AssertionError` is thrown with a `message`
941+
If `value` is not truthy, an [`AssertionError`][] is thrown with a `message`
941942
property set equal to the value of the `message` parameter. If the `message`
942943
parameter is `undefined`, a default error message is assigned. If the `message`
943944
parameter is an instance of an [`Error`][] then it will be thrown instead of the
@@ -1016,8 +1017,8 @@ an object where each property will be tested for, or an instance of error where
10161017
each property will be tested for including the non-enumerable `message` and
10171018
`name` properties.
10181019

1019-
If specified, `message` will be the message provided by the `AssertionError` if
1020-
the `asyncFn` fails to reject.
1020+
If specified, `message` will be the message provided by the [`AssertionError`][]
1021+
if the `asyncFn` fails to reject.
10211022

10221023
```js
10231024
(async () => {
@@ -1092,11 +1093,11 @@ assert.strictEqual(1, '1', new TypeError('Inputs are not identical'));
10921093
// TypeError: Inputs are not identical
10931094
```
10941095

1095-
If the values are not strictly equal, an `AssertionError` is thrown with a
1096+
If the values are not strictly equal, an [`AssertionError`][] is thrown with a
10961097
`message` property set equal to the value of the `message` parameter. If the
10971098
`message` parameter is undefined, a default error message is assigned. If the
10981099
`message` parameter is an instance of an [`Error`][] then it will be thrown
1099-
instead of the `AssertionError`.
1100+
instead of the [`AssertionError`][].
11001101

11011102
## assert.throws(fn[, error][, message])
11021103
<!-- YAML
@@ -1228,7 +1229,7 @@ assert.throws(
12281229
Custom error validation:
12291230

12301231
The function must return `true` to indicate all internal validations passed.
1231-
It will otherwise fail with an AssertionError.
1232+
It will otherwise fail with an [`AssertionError`][].
12321233

12331234
```js
12341235
assert.throws(
@@ -1292,6 +1293,7 @@ assert.throws(throwingFirst, /Second$/);
12921293
Due to the confusing notation, it is recommended not to use a string as the
12931294
second argument. This might lead to difficult-to-spot errors.
12941295

1296+
[`AssertionError`]: #assert_class_assert_assertionerror
12951297
[`Class`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes
12961298
[`ERR_INVALID_RETURN_VALUE`]: errors.html#errors_err_invalid_return_value
12971299
[`Error.captureStackTrace`]: errors.html#errors_error_capturestacktrace_targetobject_constructoropt

0 commit comments

Comments
 (0)