# Testing

> Write TypeScript runtime and type tests Use when this capability is needed.

- Skill: `tomevault-io/testing-40` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add tomevault-io/testing-40`
- Raw SKILL.md: https://api.skillmd.com/api/skills/tomevault-io/testing-40/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: tomevault-io (https://skillmd.com/u/tomevault-io)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/tomevault-io/testing-40

---


# Testing Skill

Write TypeScript runtime and type tests for this project.

## Imports

```ts
import * as test from "bun:test"
```

## Test Structure

Use `test.it` for individual tests and `test.describe` for grouping:

```ts
test.describe("MyModule", () => {
  test.it("should do something", () => {
    // test body
  })
})
```

Never use `test.test` - always use `test.it`.

## Assertion Formatting

Put each method call on a new line with 2-space indentation:

```ts
test.expect(value).toBe(expected)

test.expect(result).toEqual({ foo: "bar" })

test.expect(() => riskyOperation()).toThrow("error message")
```

## Type Assertions with expect-type

Use `expect-type` for compile-time type checking. Inline types directly - no type aliases:

```ts
// Check a value matches a type
type.expectTypeOf(someValue).toMatchObjectType<ExpectedType>()

// Check two types are exactly equal
type.expectTypeOf<ActualType>().toMatchObjectType<ExpectedType>()

// Check a type extends another (less strict)
type.expectTypeOf<SubType>().toExtend<SuperType>()
```

## Variable names

Avoid variable names that shadow imports. Use descriptive suffixes:

```ts
// Bad - shadows `test` import
const test = Route.add("/test", Route.get(Route.text("test")))

// Good
const testRoute = Route.add("/test", Route.get(Route.text("test")))
```

## describe() block

When testing multiple exported functions or logic, use describe() at the root:

```
// when testing a function, use its reference:
test.describe(PathPattern.parseSegment, () => {})

test.describe("Params", () => {})
```

Keep describe() blocks flat and never wrap them in describe(MODULE_NAME)

## File Location

Co-locate tests with source files: `Module.test.ts` alongside `Module.ts`

---
> Converted and distributed by [TomeVault](https://tomevault.io/claim/nounder) — claim your Tome and manage your conversions.
<!-- tomevault:4.0:skill_md:2026-04-11 -->

