assert: throw without args in ok
`assert.ok()` should always receive a value. Otherwise there might be a bug or it was intended to use `assert.fail()`. PR-URL: https://github.com/nodejs/node/pull/17581 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ron Korving <ron@ronkorving.nl>
This commit is contained in:
parent
f76ef50432
commit
d07c6f9739
@ -645,6 +645,11 @@ parameter is an instance of an [`Error`][] then it will be thrown instead of the
|
||||
## assert.ok(value[, message])
|
||||
<!-- YAML
|
||||
added: v0.1.21
|
||||
changes:
|
||||
- version: REPLACEME
|
||||
pr-url: https://github.com/nodejs/node/pull/17581
|
||||
description: assert.ok() will throw a `ERR_MISSING_ARGS` error.
|
||||
Use assert.fail() instead.
|
||||
-->
|
||||
* `value` {any}
|
||||
* `message` {any}
|
||||
|
@ -133,6 +133,9 @@ function getBuffer(fd, assertLine) {
|
||||
function innerOk(args, fn) {
|
||||
var [value, message] = args;
|
||||
|
||||
if (args.length === 0)
|
||||
throw new errors.TypeError('ERR_MISSING_ARGS', 'value');
|
||||
|
||||
if (!value) {
|
||||
if (message == null) {
|
||||
// Use the call as error message if possible.
|
||||
|
@ -754,6 +754,20 @@ common.expectsError(
|
||||
assert.equal(Object.keys(assert).length, Object.keys(a).length);
|
||||
/* eslint-enable no-restricted-properties */
|
||||
assert(7);
|
||||
common.expectsError(
|
||||
() => assert(),
|
||||
{
|
||||
code: 'ERR_MISSING_ARGS',
|
||||
type: TypeError
|
||||
}
|
||||
);
|
||||
common.expectsError(
|
||||
() => a(),
|
||||
{
|
||||
code: 'ERR_MISSING_ARGS',
|
||||
type: TypeError
|
||||
}
|
||||
);
|
||||
|
||||
// Test setting the limit to zero and that assert.strict works properly.
|
||||
const tmpLimit = Error.stackTraceLimit;
|
||||
|
Loading…
x
Reference in New Issue
Block a user