{"id":47200,"library":"bun-fetch-mock","title":"bun-fetch-mock","description":"A fetch mocking library designed specifically for Bun's runtime (≥1.0.0). Version 1.0.2 provides a simple API for mocking HTTP requests in Bun tests with TypeScript support. Key differentiators: zero external dependencies, first-class Bun integration (no polyfills needed), assertion helpers to verify all mocks were used, and support for dynamic responses. Released as MIT, actively maintained on GitHub.","status":"active","version":"1.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/lilienblum/bun-fetch-mock","tags":["javascript","bun","fetch","mock","testing"],"install":[{"cmd":"npm install bun-fetch-mock","lang":"bash","label":"npm"},{"cmd":"yarn add bun-fetch-mock","lang":"bash","label":"yarn"},{"cmd":"pnpm add bun-fetch-mock","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Package is ESM-only and uses named exports. Use ES import syntax.","wrong":"const { useFetchMock } = require('bun-fetch-mock')","symbol":"useFetchMock","correct":"import { useFetchMock } from 'bun-fetch-mock'"},{"note":"Type import for TypeScript users if they need the return type explicitly.","symbol":"FetchMock","correct":"import type { FetchMock } from 'bun-fetch-mock'"},{"note":"CommonJS require is not supported; use dynamic import with await.","wrong":"const { useFetchMock } = require('bun-fetch-mock')","symbol":"useFetchMock in CommonJS","correct":"const { useFetchMock } = await import('bun-fetch-mock')"}],"quickstart":{"code":"import { describe, test, expect } from 'bun:test';\nimport { useFetchMock } from 'bun-fetch-mock';\n\ndescribe('api', () => {\n  const fetchMock = useFetchMock({ baseUrl: 'https://api.example.com' });\n\n  test('mocks fetch', async () => {\n    fetchMock\n      .get('/users/1', { data: { id: 1, name: 'Ada' }, once: true })\n      .get('/users/1', { status: 404, data: { error: 'Not found' } });\n\n    const okRes = await fetch('https://api.example.com/users/1');\n    expect(await okRes.json()).toEqual({ id: 1, name: 'Ada' });\n\n    const notFoundRes = await fetch('https://api.example.com/users/1');\n    expect(notFoundRes.status).toBe(404);\n\n    fetchMock.assertAllMocksUsed();\n  });\n});","lang":"typescript","description":"Demonstrates basic usage: initialize mock inside describe, define routes, and verify all mocks are used."},"warnings":[{"fix":"Move useFetchMock() call to describe scope.","message":"Initialize useFetchMock() inside describe block, not inside test blocks","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure path consistency between mocked routes and actual fetch calls.","message":"mock.get('path') without trailing slash does not match requests with trailing slash","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Call fetchMock.assertAllMocksUsed() before the test ends.","message":"assertAllMocksUsed() must be called at the end of each test to verify all mocks were consumed","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.0.0':15 '1.0.2':17 'activ':61 'api':21 'assert':45 'bun':2,12,27,40,66 'bun-fetch-mock':1 'class':39 'depend':36 'design':9 'differenti':33 'dynam':56 'extern':35 'fetch':3,6,67 'first':38 'first-class':37 'github':64 'helper':46 'http':24 'integr':41 'javascript':65 'key':32 'librari':8 'maintain':62 'mit':60 'mock':4,7,23,50,68 'need':44 'polyfil':43 'provid':18 'releas':58 'request':25 'respons':57 'runtim':14 'simpl':20 'specif':10 'support':31,54 'test':28,69 'typescript':30 'use':52 'verifi':48 'version':16 'zero':34","created_at":"2026-06-07T16:50:18.181496+00:00","updated_at":"2026-06-07T16:50:18.181496+00:00","problems":[{"fix":"Ensure you are running tests with Bun (bun test) or polyfill fetch globally.","cause":"The package expects Bun's global fetch to be available. In Node.js or other runtimes, fetch might not be globally defined.","error":"TypeError: fetch is not defined"},{"fix":"Run 'bun add -d bun-fetch-mock' from the correct project root.","cause":"Package not installed or installed incorrectly (e.g., in wrong directory).","error":"Cannot find module 'bun-fetch-mock'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/lilienblum/bun-fetch-mock#readme","github":"https://github.com/lilienblum/bun-fetch-mock","docs":null,"changelog":null,"pypi":null,"npm":"bun-fetch-mock","openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}