fix: return arrays for list endpoints in test fetch mock
Prevents "agentList is not iterable" warnings in test output. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -7,8 +7,14 @@ import { beforeEach, vi } from "vitest";
|
||||
beforeEach(() => {
|
||||
vi.stubGlobal(
|
||||
"fetch",
|
||||
vi.fn(() =>
|
||||
Promise.resolve(new Response(JSON.stringify({}), { status: 200 })),
|
||||
),
|
||||
vi.fn((input: string | URL | Request) => {
|
||||
const url = typeof input === "string" ? input : input.toString();
|
||||
// Endpoints that return arrays need [] not {} to avoid "not iterable" errors.
|
||||
const arrayEndpoints = ["/agents", "/agents/config"];
|
||||
const body = arrayEndpoints.some((ep) => url.endsWith(ep))
|
||||
? JSON.stringify([])
|
||||
: JSON.stringify({});
|
||||
return Promise.resolve(new Response(body, { status: 200 }));
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user