-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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' 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>
- Loading branch information
Showing
3 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict'; | ||
require('../common'); | ||
const assert = require('assert'); | ||
|
||
// no args | ||
assert.throws( | ||
() => { assert.fail(); }, | ||
/^AssertionError: undefined undefined undefined$/ | ||
); | ||
|
||
// one arg = message | ||
assert.throws( | ||
() => { assert.fail('custom message'); }, | ||
/^AssertionError: custom message$/ | ||
); | ||
|
||
// two args only, operator defaults to '!=' | ||
assert.throws( | ||
() => { assert.fail('first', 'second'); }, | ||
/^AssertionError: 'first' != 'second'$/ | ||
); | ||
|
||
// three args | ||
assert.throws( | ||
() => { assert.fail('ignored', 'ignored', 'another custom message'); }, | ||
/^AssertionError: another custom message$/ | ||
); | ||
|
||
// no third arg (but a fourth arg) | ||
assert.throws( | ||
() => { assert.fail('first', 'second', undefined, 'operator'); }, | ||
/^AssertionError: 'first' operator 'second'$/ | ||
); |