The Built in Test Runner
node:test and node:assert give you tests without extra packages. Run with node --test.
Example
const test = require("node:test");
const assert = require("node:assert");
test("adds", () => { assert.strictEqual(1 + 1, 2); console.log("pass"); });Result
pass TAP version 13 # Subtest: adds ok 1 - adds --- duration_ms: 1.027872 type: 'test' ... 1..1 # tests 1 # suites 0 # pass 1 # fail 0 # cancelled 0 # skipped 0 # todo 0 # duration_ms 5.904008
Exercise
Assert equal.
assert.Equal(a, b)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.