← Cloudflare Workers / workers / runtime-apis / nodejs
assert
node:assert ↗ modul v Node.js poskytuje řadu užitečných tvrzení (assertions), která se hodí při psaní testů.
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
Viz Dokumentace Node.js pro assert ↗ s dalšími informacemi.