
Bun Test Mocking
Covers Bun's Jest-compatible mocking with mock(), spyOn(), and mock.module() for test doubles. You get standard stuff like mockReturnValue, mockImplementation, and call assertions, plus module-level mocking that works on both local files and node_modules. The spy functionality is clean for checking calls without breaking real behavior, and the mock properties (calls, results, lastCall) give you good introspection. Honestly the most useful part is mock.module() since it handles the hoisting complexity for you. If you're writing Bun tests and need to stub dependencies or track function calls, this covers the patterns without making you dig through docs.
- skills.sh installs
- 335
- GitHub stars
- 248
- last updated
- Aug 21, 2026
Install
$ npx -y skills add secondsky/claude-skills --skill bun-test-mocking --agent claude-codeInstalls into .claude/skills of the current project.
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);
Sponsors
Details
- Repository
- github.com/secondsky/claude-skills
- Category
- Testing & QA
- First seen
- Jun 3, 2026
More from secondsky/claude-skills
All 146- Nuxt Seo335
- Bun Bundler334
- Bun Workers333
- Bun Shell331
- Bun React Ssr330
- Bun Tanstack Start329
- Cloudflare Workers Performance329
- Bun Hot Reloading328
- Bun Redis328
- Bun Ffi326
- Bun Jest Migration326
- Bun Websocket Server326
- Cloudflare Workers Runtime Apis326
- Swift Best Practices326
- Bun Nuxt323
- Bun Macros322
- Cloudflare Workers Frameworks321
- Supabase Postgres Best Practices319
- Cloudflare Workers Ci Cd318
- Cloudflare Workers Dev Experience317
- Cloudflare Workers Observability315
- Cloudflare Workers Migration310
- Cloudflare Workers Multi Lang310
- Verification Before Completion310