MCPcopy
hub / github.com/colbymchenry/codegraph / mockFetch

Function mockFetch

__tests__/telemetry.test.ts:18–24  ·  view source on GitHub ↗
(calls: FetchCall[], opts: { fail?: boolean } = {})

Source from the content-addressed store, hash-verified

16type FetchCall = { url: string; body: Record<string, unknown> };
17
18function mockFetch(calls: FetchCall[], opts: { fail?: boolean } = {}) {
19 return vi.fn(async (input: RequestInfo | URL, init?: RequestInit) => {
20 if (opts.fail) throw new Error('network down');
21 calls.push({ url: String(input), body: JSON.parse(String(init?.body)) as Record<string, unknown> });
22 return new Response(null, { status: 204 });
23 }) as unknown as typeof globalThis.fetch;
24}
25
26describe('Telemetry', () => {
27 let dir: string;

Callers 2

makeFunction · 0.85
telemetry.test.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected