Skip to content
secondsky avatar

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
View on GitHub

Own this skill? Claim it

What it does

  • Covers mock functions, return values, implementations, spies, module mocks, and call assertions with mock(), spyOn(), and mock.module()
  • Includes jest.fn() compatibility, promise-returning mocks, and recipes for mocking fetch, console, and class methods
  • Documents mockClear(), mockReset(), and mockRestore() 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 -y

Installs 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

Similar to Bun Test Mocking

More Testing & QA