mirror of
https://github.com/nodejs/node.git
synced 2025-05-09 07:27:32 +00:00

Using `assert.fail()` with more than one argument is not intuitive to use and has no benefit over using a message on its own. Therefore this introduces a runtime deprecation in case it is used in that way. PR-URL: https://github.com/nodejs/node/pull/18418 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
41 lines
766 B
JavaScript
41 lines
766 B
JavaScript
'use strict';
|
|
|
|
require('../common');
|
|
const assert = require('assert');
|
|
|
|
// No args
|
|
assert.throws(
|
|
() => { assert.fail(); },
|
|
{
|
|
code: 'ERR_ASSERTION',
|
|
name: 'AssertionError [ERR_ASSERTION]',
|
|
message: 'Failed',
|
|
operator: undefined,
|
|
actual: undefined,
|
|
expected: undefined
|
|
}
|
|
);
|
|
|
|
// One arg = message
|
|
assert.throws(() => {
|
|
assert.fail('custom message');
|
|
}, {
|
|
code: 'ERR_ASSERTION',
|
|
name: 'AssertionError [ERR_ASSERTION]',
|
|
message: 'custom message',
|
|
operator: undefined,
|
|
actual: undefined,
|
|
expected: undefined
|
|
});
|
|
|
|
// One arg = Error
|
|
assert.throws(() => {
|
|
assert.fail(new TypeError('custom message'));
|
|
}, {
|
|
name: 'TypeError',
|
|
message: 'custom message',
|
|
operator: undefined,
|
|
actual: undefined,
|
|
expected: undefined
|
|
});
|