diff --git a/doc/api/assert.md b/doc/api/assert.md index f3202c214ba192..efc0f4e07856d6 100644 --- a/doc/api/assert.md +++ b/doc/api/assert.md @@ -645,6 +645,11 @@ parameter is an instance of an [`Error`][] then it will be thrown instead of the ## assert.ok(value[, message]) * `value` {any} * `message` {any} diff --git a/lib/assert.js b/lib/assert.js index a65be66ac735de..db8ae35e07ca3e 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -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. diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js index c1b32c1e5cb296..ccfe276c80a1de 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -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;