Import the Node-compatible test registration API with node:test:
import test, { describe, it } from "node:test";
test("addition", (t) => {
t.assert.strictEqual(1 + 1, 2);
});
describe("math", () => {
it("multiplies", (t) => {
t.assert.strictEqual(2 * 3, 6);
});
});Available surface
| Area | Members |
|---|---|
| Tests and suites | test / it, describe / suite, plus .skip, .todo, and .only |
| Hooks | before, after, beforeEach, afterEach |
| Test context | t.assert, t.test, hooks, t.diagnostic, t.plan, t.skip, t.todo, t.mock, t.signal |
| Mocks | mock.fn, mock.method, property/accessor mocks, fake timers, reset, and restore |
| Module assertions | test.assert |
Snapshot assertions, mock.module(), and the programmatic run() entry point are not implemented.
Execution limitation
In 1.5, importing node:test under elide run registers tests but does not
execute the test tree or emit TAP before the process exits. Use elide test
instead; it accepts an explicit JavaScript test file when run from a standalone
directory or project:
elide test ./math.test.mjs