import { LedgerClient } from '../src/lib/api'; export function fakeClient(routes: Record unknown>) { const calls: { url: string; method: string; body: unknown; headers: Record }[] = []; const client = new LedgerClient({ fetch: async (url, init) => { const body = init.body ? JSON.parse(String(init.body)) : undefined; calls.push({ url, method: String(init.method), body, headers: init.headers as Record }); const handler = routes[url.split('?')[0]]; if (!handler) return new Response(JSON.stringify({ error: '地址不存在' }), { status: 404 }); try { return new Response(JSON.stringify(handler(body)), { status: 200 }); } catch (err) { return new Response(JSON.stringify({ error: (err as Error).message }), { status: 401 }); } }, storage: window.localStorage, setTimeout: (fn, ms) => (ms === 25000 ? 0 : setTimeout(fn, 0)), clearTimeout: () => {}, randomUUID: () => 'test-operation-key-0001', }); return { client, calls }; }