home / skills / andrelandgraf / fullstackrecipes / unit-tests

unit-tests skill

/.agents/skills/unit-tests

This skill configures and runs Bun unit tests with Jest-compatible syntax, providing fast, co-located test files and robust mocking.

npx playbooks add skill andrelandgraf/fullstackrecipes --skill unit-tests

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
495 B
---
name: unit-tests
description: Configure unit testing with Bun's built-in test runner. Fast, Jest-compatible syntax, co-located test files, and mocking support.
---

# Unit Tests with Bun

To set up Unit Tests with Bun, refer to the fullstackrecipes MCP server resource:

**Resource URI:** `recipe://fullstackrecipes.com/unit-tests`

If the MCP server is not configured, fetch the recipe directly:

```bash
curl -H "Accept: text/plain" https://fullstackrecipes.com/api/recipes/unit-tests
```

Overview

This skill configures fast, Jest-compatible unit testing using Bun's built-in test runner for TypeScript projects. It provides co-located test file conventions, mocking support, and a concise recipe to get tests running quickly in full stack AI apps. The setup focuses on production-ready patterns and repeatable steps.

How this skill works

The skill installs and configures Bun's test runner and applies a Jest-like API so existing tests require minimal changes. It places tests next to implementation files, enables built-in mocking and snapshot features, and includes a recipe URI for step-by-step instructions. The result is a lightweight test environment with fast startup and native TypeScript compatibility.

When to use it

  • You need fast local unit test feedback for TypeScript services or libraries.
  • You want to reuse Jest-style tests while moving to Bun for performance.
  • You prefer co-located tests alongside implementation files for clarity.
  • You need built-in mocking and snapshot capabilities without heavy tooling.
  • You want a simple, reproducible recipe for CI and developer workstations.

Best practices

  • Co-locate test files with implementation using .test.ts or .spec.ts suffixes.
  • Keep tests focused and fast: mock external services and avoid slow integration calls.
  • Use Bun's snapshot testing for UI-like outputs and stable string comparisons.
  • Run tests locally with Bun and include the test command in CI pipelines.
  • Maintain Jest-compatible APIs to ease migration and reuse existing test code.

Example use cases

  • Adding unit tests to a new TypeScript service in a full stack AI app.
  • Migrating existing Jest tests to Bun to reduce CI and developer test time.
  • Creating fast feedback loops for model input validation and utility functions.
  • Mocking external APIs and databases during component-level testing.
  • Standardizing test layout across a monorepo using co-located test files.

FAQ

Where can I find the step-by-step recipe?

Follow the recipe at recipe://fullstackrecipes.com/unit-tests or fetch it with curl: curl -H "Accept: text/plain" https://fullstackrecipes.com/api/recipes/unit-tests

Do I need to rewrite my Jest tests?

Most Jest-style tests work as-is thanks to Bun's Jest-compatible API, though minor adjustments may be needed for environment-specific globals.