|
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: |
@@ -185,11 +189,11 @@ changes: |
185 | 189 | * `expected` {any} |
186 | 190 | * `message` {string|Error} |
187 | 191 |
|
188 | | -**Strict mode** |
| 192 | +**Strict assertion mode** |
189 | 193 |
|
190 | 194 | An alias of [`assert.deepStrictEqual()`][]. |
191 | 195 |
|
192 | | -**Legacy mode** |
| 196 | +**Legacy assertion mode** |
193 | 197 |
|
194 | 198 | > Stability: 0 - Deprecated: Use [`assert.deepStrictEqual()`][] instead. |
195 | 199 |
|
@@ -596,11 +600,11 @@ added: v0.1.21 |
596 | 600 | * `expected` {any} |
597 | 601 | * `message` {string|Error} |
598 | 602 |
|
599 | | -**Strict mode** |
| 603 | +**Strict assertion mode** |
600 | 604 |
|
601 | 605 | An alias of [`assert.strictEqual()`][]. |
602 | 606 |
|
603 | | -**Legacy mode** |
| 607 | +**Legacy assertion mode** |
604 | 608 |
|
605 | 609 | > Stability: 0 - Deprecated: Use [`assert.strictEqual()`][] instead. |
606 | 610 |
|
@@ -825,11 +829,11 @@ changes: |
825 | 829 | * `expected` {any} |
826 | 830 | * `message` {string|Error} |
827 | 831 |
|
828 | | -**Strict mode** |
| 832 | +**Strict assertion mode** |
829 | 833 |
|
830 | 834 | An alias of [`assert.notDeepStrictEqual()`][]. |
831 | 835 |
|
832 | | -**Legacy mode** |
| 836 | +**Legacy assertion mode** |
833 | 837 |
|
834 | 838 | > Stability: 0 - Deprecated: Use [`assert.notDeepStrictEqual()`][] instead. |
835 | 839 |
|
@@ -931,11 +935,11 @@ added: v0.1.21 |
931 | 935 | * `expected` {any} |
932 | 936 | * `message` {string|Error} |
933 | 937 |
|
934 | | -**Strict mode** |
| 938 | +**Strict assertion mode** |
935 | 939 |
|
936 | 940 | An alias of [`assert.notStrictEqual()`][]. |
937 | 941 |
|
938 | | -**Legacy mode** |
| 942 | +**Legacy assertion mode** |
939 | 943 |
|
940 | 944 | > Stability: 0 - Deprecated: Use [`assert.notStrictEqual()`][] instead. |
941 | 945 |
|
@@ -1395,7 +1399,7 @@ argument. |
1395 | 1399 | [`assert.ok()`]: #assert_assert_ok_value_message |
1396 | 1400 | [`assert.strictEqual()`]: #assert_assert_strictequal_actual_expected_message |
1397 | 1401 | [`assert.throws()`]: #assert_assert_throws_fn_error_message |
1398 | | -[`strict` mode]: #assert_strict_mode |
| 1402 | +[strict assertion mode]: #assert_strict_assertion_mode |
1399 | 1403 | [Abstract Equality Comparison]: https://tc39.github.io/ecma262/#sec-abstract-equality-comparison |
1400 | 1404 | [Object wrappers]: https://developer.mozilla.org/en-US/docs/Glossary/Primitive#Primitive_wrapper_objects_in_JavaScript |
1401 | 1405 | [Object.prototype.toString()]: https://tc39.github.io/ecma262/#sec-object.prototype.tostring |
|
0 commit comments