bun-bagel is a lightweight mocking library for Bun's native fetch API, enabling developers to intercept HTTP requests and return custom responses during testing. Current stable version is 1.2.0. It is experimental and actively developed. Key differentiators: built specifically for Bun runtime (not Node.js), supports URL pattern matching with wildcards, mock by method/headers, and allows responses using Bun.file. No external dependencies except TypeScript peer dependency for type definitions. Ideal for unit testing Bun applications without network calls.
npm install bun-bagelNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Basic example of mocking a fetch request with glob pattern matching and response data.
Lock versions in package.json and update accordingly.
Use wildcard patterns: 'https://example.com/api/users/*' matches any user ID.
Use only in Bun environment.
Replace 'import bagel from "bun-bagel"' with 'import { mock } from "bun-bagel"'.Use 'clearMocks' instead.
Use dynamic import or switch to ESM: import { mock } from 'bun-bagel'.Ensure mock() receives a string URL: mock('https://example.com/api', data)Use named import: import { mock } from 'bun-bagel'Check URL pattern and method/headers. Use mock() with correct options.
Ensure mock returns valid data or use Bun.file for file responses.