assert.fail([message])
新增于: v0.1.21
抛出带有提供的错误消息或默认错误消息的 AssertionError。如果 message 参数是 <Error> 的实例,则将抛出该参数而不是 AssertionError。
\Throws an AssertionError with the provided error message or a default
error message. If the message parameter is an instance of <Error> then
it will be thrown instead of the AssertionError.
import assert from 'node:assert/strict'; assert.fail(); // AssertionError [ERR_ASSERTION]: Failed assert.fail('boom'); // AssertionError [ERR_ASSERTION]: boom assert.fail(new TypeError('need array')); // TypeError: need arrayconst assert = require('node:assert/strict'); assert.fail(); // AssertionError [ERR_ASSERTION]: Failed assert.fail('boom'); // AssertionError [ERR_ASSERTION]: boom assert.fail(new TypeError('need array')); // TypeError: need array
可以使用带有两个以上参数的 assert.fail(),但不推荐使用。有关更多详细信息,请参见下文。
\Using assert.fail() with more than two arguments is possible but deprecated.
See below for further details.