assert: fix assert.fail with zero arguments
PR-URL: https://github.com/nodejs/node/pull/13974 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
7022260b55
commit
fc463639fa
@ -256,19 +256,20 @@ If the values are not equal, an `AssertionError` is thrown with a `message`
|
||||
property set equal to the value of the `message` parameter. If the `message`
|
||||
parameter is undefined, a default error message is assigned.
|
||||
|
||||
## assert.fail(message)
|
||||
## assert.fail([message])
|
||||
## assert.fail(actual, expected, message, operator)
|
||||
<!-- YAML
|
||||
added: v0.1.21
|
||||
-->
|
||||
* `actual` {any}
|
||||
* `expected` {any}
|
||||
* `message` {any}
|
||||
* `message` {any} (default: 'Failed')
|
||||
* `operator` {string} (default: '!=')
|
||||
|
||||
Throws an `AssertionError`. If `message` is falsy, the error message is set as
|
||||
the values of `actual` and `expected` separated by the provided `operator`.
|
||||
Otherwise, the error message is the value of `message`.
|
||||
If no arguments are provided at all, a default message will be used instead.
|
||||
|
||||
```js
|
||||
const assert = require('assert');
|
||||
@ -284,6 +285,9 @@ assert.fail('boom');
|
||||
|
||||
assert.fail('a', 'b');
|
||||
// AssertionError: 'a' != 'b'
|
||||
|
||||
assert.fail();
|
||||
// AssertionError: Failed
|
||||
```
|
||||
|
||||
## assert.ifError(value)
|
||||
|
@ -52,8 +52,13 @@ const assert = module.exports = ok;
|
||||
// display purposes.
|
||||
|
||||
function fail(actual, expected, message, operator, stackStartFunction) {
|
||||
if (arguments.length === 1)
|
||||
if (arguments.length === 0) {
|
||||
message = 'Failed';
|
||||
}
|
||||
if (arguments.length === 1) {
|
||||
message = actual;
|
||||
actual = undefined;
|
||||
}
|
||||
if (arguments.length === 2)
|
||||
operator = '!=';
|
||||
const errors = lazyErrors();
|
||||
|
@ -8,7 +8,7 @@ assert.throws(
|
||||
common.expectsError({
|
||||
code: 'ERR_ASSERTION',
|
||||
type: assert.AssertionError,
|
||||
message: 'undefined undefined undefined'
|
||||
message: 'Failed'
|
||||
})
|
||||
);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user