assertTrue

View sourceassertTrue(test: boolean, message: string): test is

Checks that test is truthy.

This assertion rejects every falsy value, including false, 0, '', null, and undefined. A truthy value returns undefined; a falsy value throws via throws and never returns. Unlike assert, it does not allow non-nullish falsy values such as false, 0, or ''.

Examples

assertTrue(items.length > 0, 'At least one item is required.')

Parameters

NameDescriptionDefault
test

Boolean condition to check.

—
message

Error message for a falsy condition.

—

Throws

When test is falsy.

Returns

Returns undefined when test is truthy.