Typorithm · easy

bun:test Basics

bun-test-basicsbuntestingmatcherszero-config
Saved on this device
Full lesson · 8 learning steps Open any exercise for focused practice
1

Step 1 of 8 · intro card

Learn bun:test Basics

0%

bun:test

bun:test is Bun's built-in, zero-config runner. Import test, expect, and describe from "bun:test", write Jest-style assertions, and run them with bun test. Matchers like toBe, toEqual, and toThrow behave just like Jest's.

bun:test is Bun's built-in test runner: import test, expect, and describe from "bun:test", then run the suite with bun test — no Jest or Vitest install and no config file.

The expect API is Jest-compatible, so matchers like toBe (strict equality), toEqual (deep equality), and toThrow (asserts a function throws) all work exactly as you would expect.

Because the runner ships inside Bun and transpiles TypeScript directly, tests are fast to start and need zero setup before the first bun test.

01

Import test, expect, describe from "bun:test".

02

Run tests with bun test — zero config.

03

Jest matchers toBe, toEqual, toThrow all work.

import { test, expect, describe } from "bun:test";

describe("math", () => {
  test("adds numbers", () => {
    expect(2 + 2).toBe(4);
    expect({ a: 1 }).toEqual({ a: 1 });
    expect(() => { throw new Error("boom"); }).toThrow("boom");
  });
});

Read the implementation

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

1. Import the runner

test, expect, and describe come from the built-in bun:test module — nothing to install.

import { test, expect, describe } from "bun:test";

2. Group with describe

describe groups related tests under a shared label for readable output.

describe("math", () => {

3. toBe matcher

toBe checks strict (===) equality, ideal for primitives like numbers.

expect(2 + 2).toBe(4);

4. toEqual matcher

toEqual compares objects and arrays deeply by value, not by reference.

expect({ a: 1 }).toEqual({ a: 1 });

5. toThrow matcher

toThrow asserts the wrapped function throws, optionally matching the message.

}).toThrow("boom");

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.

bun:test Basics: Lesson & Practice · Typorithm | ApplyDjinn