|
5 | 5 | > Stability: 2 - Stable
|
6 | 6 |
|
7 | 7 | The `assert` module provides a set of assertion functions for verifying
|
8 |
| -invariants. The module provides a recommended [`strict` mode][] and a more |
9 |
| -lenient legacy mode. |
| 8 | +invariants. The module provides a recommended [strict assertion mode][] |
| 9 | +and a more lenient legacy assertion mode. |
10 | 10 |
|
11 | 11 | ## Class: assert.AssertionError
|
12 | 12 |
|
@@ -68,26 +68,30 @@ try {
|
68 | 68 | }
|
69 | 69 | ```
|
70 | 70 |
|
71 |
| -## Strict mode |
| 71 | +## Strict assertion mode |
72 | 72 | <!-- YAML
|
73 | 73 | added: v9.9.0
|
74 | 74 | changes:
|
| 75 | + - version: REPLACEME |
| 76 | + description: Changed "strict mode" to "strict assertion mode" and "legacy |
| 77 | + mode" to "legacy assertion mode" to avoid confusion with the |
| 78 | + more usual meaining of "strict mode". |
75 | 79 | - version: v9.9.0
|
76 | 80 | pr-url: https://github.com/nodejs/node/pull/17615
|
77 |
| - description: Added error diffs to the strict mode |
| 81 | + description: Added error diffs to the strict assertion mode. |
78 | 82 | - version: v9.9.0
|
79 | 83 | pr-url: https://github.com/nodejs/node/pull/17002
|
80 |
| - description: Added strict mode to the assert module. |
| 84 | + description: Added strict assertion mode to the assert module. |
81 | 85 | -->
|
82 | 86 |
|
83 |
| -In `strict` mode (not to be confused with `"use strict"`), `assert` functions |
84 |
| -use the comparison in the corresponding strict functions. For example, |
85 |
| -[`assert.deepEqual()`][] will behave like [`assert.deepStrictEqual()`][]. |
| 87 | +In strict assertion mode, `assert` functions use the comparison in the |
| 88 | +corresponding strict functions. For example, [`assert.deepEqual()`][] will |
| 89 | +behave like [`assert.deepStrictEqual()`][]. |
86 | 90 |
|
87 |
| -In `strict` mode, error messages for objects display a diff. In legacy mode, |
88 |
| -error messages for objects display the objects, often truncated. |
| 91 | +In strict assertion mode, error messages for objects display a diff. In legacy |
| 92 | +assertion mode, error messages for objects display the objects, often truncated. |
89 | 93 |
|
90 |
| -To use `strict` mode: |
| 94 | +To use strict assertion mode: |
91 | 95 |
|
92 | 96 | ```js
|
93 | 97 | const assert = require('assert').strict;
|
@@ -121,22 +125,22 @@ This will also deactivate the colors in the REPL.
|
121 | 125 | For more on the color support in terminal environments, read
|
122 | 126 | the tty [getColorDepth()](tty.html#tty_writestream_getcolordepth_env) doc.
|
123 | 127 |
|
124 |
| -## Legacy mode |
| 128 | +## Legacy assertion mode |
125 | 129 |
|
126 |
| -Legacy mode uses the [Abstract Equality Comparison][] in: |
| 130 | +Legacy assertion mode uses the [Abstract Equality Comparison][] in: |
127 | 131 |
|
128 | 132 | * [`assert.deepEqual()`][]
|
129 | 133 | * [`assert.equal()`][]
|
130 | 134 | * [`assert.notDeepEqual()`][]
|
131 | 135 | * [`assert.notEqual()`][]
|
132 | 136 |
|
133 |
| -To use legacy mode: |
| 137 | +To use legacy assertion mode: |
134 | 138 |
|
135 | 139 | ```js
|
136 | 140 | const assert = require('assert');
|
137 | 141 | ```
|
138 | 142 |
|
139 |
| -Whenever possible, use the [`strict` mode][] instead. Otherwise, the |
| 143 | +Whenever possible, use the [strict assertion mode][] instead. Otherwise, the |
140 | 144 | [Abstract Equality Comparison][] may cause surprising results. This is
|
141 | 145 | especially true for [`assert.deepEqual()`][], where the comparison rules are
|
142 | 146 | lax:
|
@@ -189,11 +193,11 @@ changes:
|
189 | 193 | * `expected` {any}
|
190 | 194 | * `message` {string|Error}
|
191 | 195 |
|
192 |
| -**Strict mode** |
| 196 | +**Strict assertion mode** |
193 | 197 |
|
194 | 198 | An alias of [`assert.deepStrictEqual()`][].
|
195 | 199 |
|
196 |
| -**Legacy mode** |
| 200 | +**Legacy assertion mode** |
197 | 201 |
|
198 | 202 | > Stability: 0 - Deprecated: Use [`assert.deepStrictEqual()`][] instead.
|
199 | 203 |
|
@@ -606,11 +610,11 @@ changes:
|
606 | 610 | * `expected` {any}
|
607 | 611 | * `message` {string|Error}
|
608 | 612 |
|
609 |
| -**Strict mode** |
| 613 | +**Strict assertion mode** |
610 | 614 |
|
611 | 615 | An alias of [`assert.strictEqual()`][].
|
612 | 616 |
|
613 |
| -**Legacy mode** |
| 617 | +**Legacy assertion mode** |
614 | 618 |
|
615 | 619 | > Stability: 0 - Deprecated: Use [`assert.strictEqual()`][] instead.
|
616 | 620 |
|
@@ -842,11 +846,11 @@ changes:
|
842 | 846 | * `expected` {any}
|
843 | 847 | * `message` {string|Error}
|
844 | 848 |
|
845 |
| -**Strict mode** |
| 849 | +**Strict assertion mode** |
846 | 850 |
|
847 | 851 | An alias of [`assert.notDeepStrictEqual()`][].
|
848 | 852 |
|
849 |
| -**Legacy mode** |
| 853 | +**Legacy assertion mode** |
850 | 854 |
|
851 | 855 | > Stability: 0 - Deprecated: Use [`assert.notDeepStrictEqual()`][] instead.
|
852 | 856 |
|
@@ -953,11 +957,11 @@ changes:
|
953 | 957 | * `expected` {any}
|
954 | 958 | * `message` {string|Error}
|
955 | 959 |
|
956 |
| -**Strict mode** |
| 960 | +**Strict assertion mode** |
957 | 961 |
|
958 | 962 | An alias of [`assert.notStrictEqual()`][].
|
959 | 963 |
|
960 |
| -**Legacy mode** |
| 964 | +**Legacy assertion mode** |
961 | 965 |
|
962 | 966 | > Stability: 0 - Deprecated: Use [`assert.notStrictEqual()`][] instead.
|
963 | 967 |
|
@@ -1418,7 +1422,7 @@ argument.
|
1418 | 1422 | [`assert.ok()`]: #assert_assert_ok_value_message
|
1419 | 1423 | [`assert.strictEqual()`]: #assert_assert_strictequal_actual_expected_message
|
1420 | 1424 | [`assert.throws()`]: #assert_assert_throws_fn_error_message
|
1421 |
| -[`strict` mode]: #assert_strict_mode |
| 1425 | +[strict assertion mode]: #assert_strict_assertion_mode |
1422 | 1426 | [Abstract Equality Comparison]: https://tc39.github.io/ecma262/#sec-abstract-equality-comparison
|
1423 | 1427 | [Object wrappers]: https://developer.mozilla.org/en-US/docs/Glossary/Primitive#Primitive_wrapper_objects_in_JavaScript
|
1424 | 1428 | [Object.prototype.toString()]: https://tc39.github.io/ecma262/#sec-object.prototype.tostring
|
|
0 commit comments