Bun Mocks
Learn how to create and use mock functions, spies, and module mocks in Bun tests
Install
npx skills add jarle/bun-skills --skill Bun Mocksgit clone --depth 1 https://github.com/jarle/bun-skills.git /tmp/bun-skills
mkdir -p ~/.claude/skills
cp -r /tmp/bun-skills/skills/bun-test-mocks ~/.claude/skills/Bun-MocksPersonal skills live in ~/.claude/skills. Use .claude/skills in a project folder to share a skill with your team.
From the SKILL.md
# Mocks
> Learn how to create and use mock functions, spies, and module mocks in Bun tests
Mocking is essential for testing by allowing you to replace dependencies with controlled implementations. Bun provides comprehensive mocking capabilities including function mocks, spies, and module mocks.
## Basic Function Mocks
Create mocks with the `mock` function.
```ts title="test.ts" icon="https://mintcdn.com/bun-1dd33a4e/nIz6GtMH5K-dfXeV/icons/typescript.svg?fit=max&auto=format&n=nIz6GtMH5K-dfXeV&q=85&s=5d73d76daf7eb7b158469d8c30d349b0" theme={"theme":{"light":"github-light","dark":"dracula"}}
import { test, expect, mock } from "bun:test";
const random = mock(() => Math.random());
test("random", () => {
const val = random();
expect(val).toBeGreaterThan(0);
expect(random).toHaveBeenCalled();
expect(random).toHaveBeenCalledTimes(1);
});
```
### Jest Compatibility
Alternatively, you can use the `jest.fn()` function, as in Jest. It behaves identically.
```ts title="test.ts" icon="https://mintcdn.com/bun-1dd33a4e/nIz6GtMH5K-dfXeV/icons/typescript.svg?fit=max&auto=format&n=nIz6GtMH5K-dfXeV&q=85&s=5d73d76daf7eb7b158469d8c30d349b0" theme={"theme":{"light":"github-light","dark":"dracula"}}
import { test, expect, jest } from "bun:test";
const random = jest.fn(() => Math.random());
test("random", () => {
const val = random();
expect(val).toBeGreaterThan(0);
expect(random).toHaveBeenCalled();
expect(random).toHaveBeenCalledTimes(1);
});
```Details
- Skill name
Bun Mocks- Repository
- jarle/bun-skills
- Path
skills/bun-test-mocks/SKILL.md- License
- MIT
- Repo updated
- 24 February 2026
FAQ
What does the Bun Mocks skill do?
Learn how to create and use mock functions, spies, and module mocks in Bun tests
How do I install the Bun Mocks skill?
skills CLI (Claude Code, Cursor, Codex and more): npx skills add jarle/bun-skills --skill Bun Mocks. Skills go in ~/.claude/skills (personal) or .claude/skills (project), and Claude loads them automatically when a task matches the description.
Is Bun Mocks popular?
It lives in jarle/bun-skills, which has 9 GitHub stars and 1 forks.
Related skills
Bun Archive
9jarle/bun-skills
Create and extract tar archives with Bun's fast native implementation
Bun Auto Install
9jarle/bun-skills
Bun's automatic package installation feature for standalone script execution
Bun Bun Add
9jarle/bun-skills
Add packages to your project with Bun's fast package manager
Bun Re Run Tests Multiple Times with the Bun Test Runner
9jarle/bun-skills
Re-run tests multiple times with the Bun test runner
Bun Lifecycle Hooks
9jarle/bun-skills
Learn how to use beforeAll, beforeEach, afterEach, and afterAll lifecycle hooks in Bun tests
Bun Runtime Behavior
9jarle/bun-skills
Learn about Bun test's runtime integration, environment variables, timeouts, and error handling
Browse the most popular Claude skills, all testing & qa skills, or write your own with the skills generator.