assert
The assert
module in Node.js provides a number of useful assertions that are useful when building tests.
import {strictEqual,deepStrictEqual,ok,doesNotReject,} from 'node:assert';strictEqual(1, 1); // ok!strictEqual(1, "1"); // fails! throws AssertionErrordeepStrictEqual({ a: { b: 1 }}, { a: { b: 1 }});// ok!deepStrictEqual({ a: { b: 1 }}, { a: { b: 2 }});// fails! throws AssertionErrorok(true); // ok!ok(false); // fails! throws AssertionErrorawait doesNotReject(async () => {}); // ok!await doesNotReject(async () => { throw new Error('boom') }); // fails! throws AssertionError
Refer to the
Node.js documentation for assert
for more information.