Skip to content

Commit 6fe7cac

Browse files
committed
Extend mock Response shape to cover error paths
Add missing fields to mock Response objects: - Success case: status, statusText - Error case: statusText, text() This ensures the mock matches McpdClient expectations for non-2xx responses and prevents runtime errors when tests hit unmapped routes.
1 parent 68e3de3 commit 6fe7cac

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

tests/unit/utils/mockApi.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,27 @@ export function createFetchMock(routes: Record<string, unknown>): typeof fetch {
3535

3636
if (match) {
3737
const [, payload] = match;
38-
return { ok: true, json: async () => payload } as Response;
38+
return {
39+
ok: true,
40+
status: 200,
41+
statusText: "OK",
42+
json: async () => payload,
43+
} as Response;
3944
}
4045

46+
const payload = {
47+
status: 404,
48+
title: "Not Found",
49+
detail: "Route not found",
50+
type: "about:blank",
51+
};
52+
4153
return {
4254
ok: false,
4355
status: 404,
44-
json: async () => ({
45-
status: 404,
46-
title: "Not Found",
47-
detail: "Route not found",
48-
type: "about:blank",
49-
}),
56+
statusText: "Not Found",
57+
json: async () => payload,
58+
text: async () => JSON.stringify(payload),
5059
} as Response;
5160
});
5261

0 commit comments

Comments
 (0)