@@ -415,30 +415,64 @@ parameter is an instance of an [`Error`][] then it will be thrown instead of the
415
415
` AssertionError ` .
416
416
417
417
## assert.fail([ message] )
418
+ <!-- YAML
419
+ added: v0.1.21
420
+ -->
421
+ * ` message ` {any} ** Default:** ` 'Failed' `
422
+
423
+ Throws an ` AssertionError ` with the provided error message or a default error
424
+ message. If the ` message ` parameter is an instance of an [ ` Error ` ] [ ] then it
425
+ will be thrown instead of the ` AssertionError ` .
426
+
427
+ ``` js
428
+ const assert = require (' assert' ).strict ;
429
+
430
+ assert .fail ();
431
+ // AssertionError [ERR_ASSERTION]: Failed
432
+
433
+ assert .fail (' boom' );
434
+ // AssertionError [ERR_ASSERTION]: boom
435
+
436
+ assert .fail (new TypeError (' need array' ));
437
+ // TypeError: need array
438
+ ```
439
+
440
+ Using ` assert.fail() ` with more than two arguments is possible but deprecated.
441
+ See below for further details.
442
+
418
443
## assert.fail(actual, expected[ , message[ , operator[ , stackStartFunction]]] )
419
444
<!-- YAML
420
445
added: v0.1.21
446
+ changes:
447
+ - version: REPLACEME
448
+ pr-url: https://github.com/nodejs/node/pull/REPLACEME
449
+ description: Calling `assert.fail` with more than one argument is deprecated
450
+ and emits a warning.
421
451
-->
422
452
* ` actual ` {any}
423
453
* ` expected ` {any}
424
- * ` message ` {any} ** Default: ** ` 'Failed' `
454
+ * ` message ` {any}
425
455
* ` operator ` {string} ** Default:** '!='
426
456
* ` stackStartFunction ` {Function} ** Default:** ` assert.fail `
427
457
428
- Throws an ` AssertionError ` . If ` message ` is falsy, the error message is set as
429
- the values of ` actual ` and ` expected ` separated by the provided ` operator ` . If
430
- the ` message ` parameter is an instance of an [ ` Error ` ] [ ] then it will be thrown
431
- instead of the ` AssertionError ` . If just the two ` actual ` and ` expected `
432
- arguments are provided, ` operator ` will default to ` '!=' ` . If ` message ` is
433
- provided only it will be used as the error message, the other arguments will be
434
- stored as properties on the thrown object. If ` stackStartFunction ` is provided,
435
- all stack frames above that function will be removed from stacktrace (see
436
- [ ` Error.captureStackTrace ` ] ). If no arguments are given, the default message
437
- ` Failed ` will be used.
458
+ > Stability: 0 - Deprecated: Use ` assert.fail([message]) ` or other assert
459
+ > functions instead.
460
+
461
+ If ` message ` is falsy, the error message is set as the values of ` actual ` and
462
+ ` expected ` separated by the provided ` operator ` . If just the two ` actual ` and
463
+ ` expected ` arguments are provided, ` operator ` will default to ` '!=' ` . If
464
+ ` message ` is provided as third argument it will be used as the error message and
465
+ the other arguments will be stored as properties on the thrown object. If
466
+ ` stackStartFunction ` is provided, all stack frames above that function will be
467
+ removed from stacktrace (see [ ` Error.captureStackTrace ` ] ). If no arguments are
468
+ given, the default message ` Failed ` will be used.
438
469
439
470
``` js
440
471
const assert = require (' assert' ).strict ;
441
472
473
+ assert .fail (' a' , ' b' );
474
+ // AssertionError [ERR_ASSERTION]: 'a' != 'b'
475
+
442
476
assert .fail (1 , 2 , undefined , ' >' );
443
477
// AssertionError [ERR_ASSERTION]: 1 > 2
444
478
@@ -452,21 +486,11 @@ assert.fail(1, 2, new TypeError('need array'));
452
486
// TypeError: need array
453
487
```
454
488
455
- * Note * : In the last two cases ` actual ` , ` expected ` , and ` operator ` have no
489
+ In the last three cases ` actual ` , ` expected ` , and ` operator ` have no
456
490
influence on the error message.
457
491
458
- ``` js
459
- assert .fail ();
460
- // AssertionError [ERR_ASSERTION]: Failed
461
-
462
- assert .fail (' boom' );
463
- // AssertionError [ERR_ASSERTION]: boom
464
-
465
- assert .fail (' a' , ' b' );
466
- // AssertionError [ERR_ASSERTION]: 'a' != 'b'
467
- ```
468
-
469
492
Example use of ` stackStartFunction ` for truncating the exception's stacktrace:
493
+
470
494
``` js
471
495
function suppressFrame () {
472
496
assert .fail (' a' , ' b' , undefined , ' !==' , suppressFrame);
0 commit comments