Bun Test Mocking
Jest-compatible mocking for Bun tests covering mock functions, spies, and module replacement.
- CCM score
- 52 of 100
- skills.sh installs
- 430
- GitHub stars
- 257
- last updated
- Aug 21, 2026
Own this skill? Claim it
What it does
- Covers mock functions, return values, implementations, spies, module mocks, and call assertions with
mock(),spyOn(), andmock.module() - Includes
jest.fn()compatibility, promise-returning mocks, and recipes for mockingfetch,console, and class methods - Documents
mockClear(),mockReset(), andmockRestore()for resetting call history, implementations, and spies between tests - Designed for Bun projects that need test doubles, with reference files for the full mock API and module hoisting details
Install
$ npx -y skills add secondsky/claude-skills --skill bun-test-mocking -yInstalls into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.
Files
Bun Test Mocking
Bun provides Jest-compatible mocking with mock(), spyOn(), and module mocking.
Mock Functions
import { test, expect, mock } from "bun:test";
// Create mock function
const fn = mock(() => "original");
test("mock function", () => {
fn("arg1", "arg2");
expect(fn).toHaveBeenCalled();
expect(fn).toHaveBeenCalledTimes(1);
expect(fn).toHaveBeenCalledWith("arg1", "arg2");
});
jest.fn() Compatibility
import { test, expect, jest } from "bun:test";
const fn = jest.fn(() => "value");
test("jest.fn works", () => {
const result = fn();
expect(result).toBe("value");
expect(fn).toHaveBeenCalled();
});
Mock Return Values
const fn = mock();
// Return value once
fn.mockReturnValueOnce("first");
fn.mockReturnValueOnce("second");
// Permanent return value
fn.mockReturnValue("default");
// Promise returns
fn.mockResolvedValue("resolved");
fn.mockResolvedValueOnce("once");
fn.mockRejectedValue(new Error("fail"));
fn.mockRejectedValueOnce(new Error("once"));
Mock Implementations
const fn = mock();
// Set implementation
fn.mockImplementation((x) => x * 2);
Details
- Repository
- github.com/secondsky/claude-skills
- Category
- Testing & QA
- First seen
- Jun 3, 2026
Questions
What does the bun-test-mocking skill help with?
bun-test-mocking covers mock functions in Bun tests, including spyOn, mock.module, mock implementations and test doubles. It shows how to set return values, mock promises, spy on methods and fetch, and assert on mock calls.
How do I install the bun-test-mocking skill?
Run npx -y skills add secondsky/claude-skills --skill bun-test-mocking -y in your project. Once installed, bun-test-mocking lets your agent write Bun tests that use mock(), spyOn() and mock.module() with Jest-compatible assertions.
Where does bun-test-mocking sit among Testing and QA skills?
bun-test-mocking is in the Testing and QA category on Claude Marketplaces. Other skills in that category include tdd, test-driven-development and webapp-testing. bun-test-mocking sets itself apart by focusing on Bun's mocking API, including mock.module for replacing whole modules.
Does bun-test-mocking work with jest.fn()?
Yes, bun-test-mocking documents jest.fn() compatibility under Bun's bun:test module. Its examples show jest.fn() returning values and being checked with toHaveBeenCalled, so Jest-style test code can move over to Bun with little change.
More from secondsky/claude-skills
All 116- Mobile Offline Support428
- Bun Test Coverage427
- Api Changelog Versioning426
- Dependency Upgrade426
- Idempotency Handling426
- Nuxt Server426
- Bun Cloudflare Workers425
- Bun Workers425
- Bun Http Server424
- Bun Bundler423
- Turborepo423
- Api Versioning Strategy421
- Recommendation System421
- Logging Best Practices419
- Bun Hot Reloading418
- Claude Hook Writer418
- Claude Code Bash Patterns417
- Plan Interview417
- Bun React Ssr416
- Bun Shell416
- Bun Websocket Server414
- Bun Redis412
- Ml Pipeline Automation412
- Nuxt Core411
Similar to Bun Test Mocking
More Testing & QAbun-jest-migrationsecondsky/claude-skills408 installsStep-by-step guide that moves a Jest test suite to Bun's runner, covering imports, mocks, timers, and config.
mocking-stubbingaj-geddes/useful-ai-prompts435 installsStructured guide for isolating unit tests with mocks, stubs, spies, and test doubles across Jest, unittest.mock, and Mockito.
jestmindrally/skills929 installsJest testing guidance for JavaScript and TypeScript covering structure, mocking, assertions, and async patterns.
jest-generatorsecondsky/claude-skills402 installsGenerates Jest unit tests for JavaScript and TypeScript with mocking, async handling, and React component coverage.
javascript-testing-patternswshobson/agents21.8K installsComprehensive testing guide covering Jest and Vitest setup, unit, async, and mocking patterns for JavaScript and TypeScript.
javascript-typescript-jestgithub/awesome-copilot14.8K installsBest practices for Jest tests in JavaScript and TypeScript covering structure, mocking, async code, and React.