Typorithm · medium

node:test Runner

node-test-runnernodejstest-runnersubtestsmock
Saved on this device
Full lesson · 8 learning steps Open any exercise for focused practice
1

Step 1 of 8 · intro card

Learn node:test Runner

0%

Testing & Debug

node:test is Node's built-in test runner — import { test, describe } from "node:test" and run with node --test. describe groups subtests, test.skip/only filter the run, async tests work by returning a promise, and the node:test mock module (mock.fn, mock.method) handles stubbing.

Node ships a built-in runner in the node:test module, so you import { test, describe } from "node:test" and execute the suite with node --test — no third-party runner required.

describe groups related cases and the test calls nested inside it become subtests; test.skip skips a case while test.only narrows the run to only the marked tests.

An async test is just a function that returns a promise — the runner awaits it and fails if it rejects — and the node:test mock module provides mock.fn and mock.method for stubbing.

01

import { test, describe } from "node:test"; run with node --test.

02

describe groups subtests; test.skip/only filter the run.

03

Async tests return a promise; mock.fn/mock.method stub.

import { test, describe } from "node:test";

describe("math", () => {
  test("adds", () => {
    if (1 + 1 !== 2) throw new Error("bad");
  });
  test.skip("later", () => {});
});

test("async", async () => {
  await Promise.resolve();
});

Read the implementation

Connect each part of the code to the concept before you type.

1. Built-in runner

test and describe come straight from the node:test built-in module — no Jest or Vitest install needed.

import { test, describe } from "node:test";

2. Group with describe

describe groups related tests; test calls inside it become subtests of that suite.

describe("math", () => {

3. Skip a test

test.skip marks a test as skipped; test.only restricts the run to just the marked tests.

test.skip("later", () => {});

4. Async test

An async test returns a promise; the runner awaits it and fails the test if the promise rejects.

test("async", async () => {

5. Await inside

Awaiting inside the test lets the runner track completion before reporting pass or fail.

await Promise.resolve();

A complete learning loop

01

Understand

Read the concept map and follow the code breakdown.

02

Reconstruct

Type the implementation, repair mistakes and work through every recall exercise.

03

Verify

Use the final check without hints; revisit weak concepts in short practice sessions.

node:test Runner: Lesson & Practice · Typorithm | ApplyDjinn