Cloudflare Docs
Workers
Edit this page
Give us feedback
Set theme to dark (⇧+D)

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 AssertionError
deepStrictEqual({ a: { b: 1 }}, { a: { b: 1 }});// ok!
deepStrictEqual({ a: { b: 1 }}, { a: { b: 2 }});// fails! throws AssertionError
ok(true); // ok!
ok(false); // fails! throws AssertionError
await doesNotReject(async () => {}); // ok!
await doesNotReject(async () => { throw new Error('boom') }); // fails! throws AssertionError

Refer to the Node.js documentation for assert for more information.