MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / mockFetch

Function mockFetch

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

Source from the content-addressed store, hash-verified

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

Callers 2

makeFunction · 0.85
telemetry.test.tsFile · 0.85

Calls 2

pushMethod · 0.80
parseMethod · 0.80

Tested by

no test coverage detected