node:test API Reference

Node.js test registration, suites, hooks, assertions, and mocks

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

AreaMembers
Tests and suitestest / it, describe / suite, plus .skip, .todo, and .only
Hooksbefore, after, beforeEach, afterEach
Test contextt.assert, t.test, hooks, t.diagnostic, t.plan, t.skip, t.todo, t.mock, t.signal
Mocksmock.fn, mock.method, property/accessor mocks, fake timers, reset, and restore
Module assertionstest.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

See also