Commit 4917d8c
assert: improve assert.fail() API
assert.fail() has two possible function signatures, both of which are
not intuitive. It virtually guarantees that people who try to use
assert.fail() without carefully reading the docs will end up using it
incorrectly.
This change maintains backwards compatibility with the two valid uses
(arguments 1 2 and 4 supplied but argument 3 falsy, and argument 3
supplied but arguments 1 2 and 4 all falsy) but also adds the far more
intuitive first-argument-only and first-two-arguments-only
possibilities.
assert.fail('boom');
// AssertionError: boom
assert.fail('a', 'b');
// AssertionError: 'a' != 'b'
Backport-PR-URL: #15479
PR-URL: #12293
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>1 parent a7d4cad commit 4917d8cCopy full SHA for 4917d8c
File tree
Expand file treeCollapse file tree
3 files changed
+42
-1
lines changedOpen diff view settings
Filter options
- doc/api
- lib
- test/parallel
Expand file treeCollapse file tree
3 files changed
+42
-1
lines changedOpen diff view settings
Collapse file
+8-1Lines changed: 8 additions & 1 deletion
- Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
194 | 194 | |
195 | 195 | |
196 | 196 | |
| 197 | + |
197 | 198 | |
198 | 199 | |
199 | 200 | |
200 | 201 | |
201 | 202 | |
202 | 203 | |
203 | 204 | |
204 | | - |
| 205 | + |
205 | 206 | |
206 | 207 | |
207 | 208 | |
| ||
221 | 222 | |
222 | 223 | |
223 | 224 | |
| 225 | + |
| 226 | + |
| 227 | + |
| 228 | + |
| 229 | + |
| 230 | + |
224 | 231 | |
225 | 232 | |
226 | 233 | |
|
Collapse file
+4Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
77 | 77 | |
78 | 78 | |
79 | 79 | |
| 80 | + |
| 81 | + |
| 82 | + |
| 83 | + |
80 | 84 | |
81 | 85 | |
82 | 86 | |
|
Collapse file
test/parallel/test-assert-fail.js
Copy file name to clipboardExpand all lines: test/parallel/test-assert-fail.js+30Lines changed: 30 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
3 | 3 | |
4 | 4 | |
5 | 5 | |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | + |
6 | 36 | |
7 | 37 | |
8 | 38 | |
|
0 commit comments