Skip to main content

fail

function assert.fail
Jump to headingfail(message?: string | Error): never

Throws an AssertionError with the provided error message or a default error message. If the message parameter is an instance of an 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 array

Using assert.fail() with more than two arguments is possible but deprecated. See below for further details.

Parameters Jump to heading

optional
Jump to headingmessage: string | Error = 'Failed'

Return Type Jump to heading

never
Jump to headingfail(
actual: unknown,
expected: unknown,
message?: string | Error,
operator?: string,
stackStartFn?: Function,
): never
Deprecated

Parameters Jump to heading

Jump to headingactual: unknown
Jump to headingexpected: unknown
optional
Jump to headingmessage: string | Error
optional
Jump to headingoperator: string
optional
Jump to headingstackStartFn: Function

Return Type Jump to heading

never
Back to top