Skip to content
This repository was archived by the owner on Dec 27, 2025. It is now read-only.

Commit 83e7c04

Browse files
committed
fix(test): align mock response objects with actual type definitions
Mock response objects in failure test scenarios used functions instead of getters/direct values, causing TypeScript type errors after dependency updates. HTTP responses now use getters for arrayBuffer, blob, text, json, and raw properties to match HttpResponseError/Success interfaces. ConnectRPC and GraphQL responses now use direct values for data and raw properties instead of functions. This ensures mock objects conform to the actual client library type definitions, preventing type checking failures when libraries update their response interfaces.
1 parent 7e32759 commit 83e7c04

4 files changed

Lines changed: 44 additions & 30 deletions

File tree

probitas/90-failure-http.probitas.ts

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,23 @@ function createMockErrorResponse(
3333
headers: new Headers({ "content-type": "application/json" }),
3434
url: "http://example.com/api",
3535
body: bodyBytes,
36-
arrayBuffer: () => bodyBytes.buffer,
37-
blob: () => new Blob([bodyBytes]),
38-
text: () => '{"error":"something went wrong"}',
36+
get arrayBuffer() {
37+
return bodyBytes.buffer;
38+
},
39+
get blob() {
40+
return new Blob([bodyBytes]);
41+
},
42+
get text() {
43+
return '{"error":"something went wrong"}';
44+
},
3945
// deno-lint-ignore no-explicit-any
40-
json: <T = any>(): T | null => ({ error: "something went wrong" }) as T,
46+
get json(): any {
47+
return { error: "something went wrong" };
48+
},
4149
duration: 1500,
42-
raw: () => rawResponse,
50+
get raw() {
51+
return rawResponse;
52+
},
4353
error: new HttpError(500, "Internal Server Error", {
4454
headers: new Headers({ "content-type": "application/json" }),
4555
body: bodyBytes,
@@ -68,13 +78,23 @@ function createMockSuccessResponse(
6878
headers: new Headers({ "content-type": "application/json" }),
6979
url: "http://example.com/api",
7080
body: bodyBytes,
71-
arrayBuffer: () => bodyBytes.buffer,
72-
blob: () => new Blob([bodyBytes]),
73-
text: () => '{"status":"ok"}',
81+
get arrayBuffer() {
82+
return bodyBytes.buffer;
83+
},
84+
get blob() {
85+
return new Blob([bodyBytes]);
86+
},
87+
get text() {
88+
return '{"status":"ok"}';
89+
},
7490
// deno-lint-ignore no-explicit-any
75-
json: <T = any>(): T | null => ({ status: "ok" }) as T,
91+
get json(): any {
92+
return { status: "ok" };
93+
},
7694
duration: 100,
77-
raw: () => rawResponse,
95+
get raw() {
96+
return rawResponse;
97+
},
7898
error: null,
7999
};
80100
return { ...defaultResponse, ...overrides };

probitas/91-failure-grpc.probitas.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,10 @@ function createMockErrorResponse(): GrpcResponse {
2828
statusMessage: "Resource not found",
2929
headers: new Headers({ "grpc-status": "5" }),
3030
trailers: new Headers({ "grpc-message": "not found" }),
31-
// deno-lint-ignore no-explicit-any
32-
data: <T = any>(): T | null => null,
31+
data: null,
3332
duration: 250,
3433
// deno-lint-ignore no-explicit-any
35-
raw: () => error as any,
34+
raw: error as any,
3635
};
3736
return response;
3837
}

probitas/92-failure-connectrpc.probitas.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,10 @@ function createMockErrorResponse(): ConnectRpcResponse {
2828
statusMessage: "Invalid argument provided",
2929
headers: new Headers({ "content-type": "application/proto" }),
3030
trailers: new Headers(),
31-
// deno-lint-ignore no-explicit-any
32-
data: <T = any>(): T | null => null,
31+
data: null,
3332
duration: 150,
3433
// deno-lint-ignore no-explicit-any
35-
raw: () => error as any,
34+
raw: error as any,
3635
};
3736
return response;
3837
}

probitas/93-failure-graphql.probitas.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,12 @@ function createMockErrorResponse(): GraphqlResponseError {
3737
status: 200,
3838
headers: new Headers({ "content-type": "application/json" }),
3939
extensions: { code: "VALIDATION_ERROR" },
40-
// deno-lint-ignore no-explicit-any
41-
data: <T = any>(): T | null => null,
40+
data: null,
4241
duration: 300,
43-
raw: () =>
44-
new Response('{"errors":[{"message":"Field not found"}]}', {
45-
status: 200,
46-
headers: { "content-type": "application/json" },
47-
}),
42+
raw: new Response('{"errors":[{"message":"Field not found"}]}', {
43+
status: 200,
44+
headers: { "content-type": "application/json" },
45+
}),
4846
};
4947
return response;
5048
}
@@ -60,14 +58,12 @@ function createMockSuccessResponse(): GraphqlResponseSuccess {
6058
status: 200,
6159
headers: new Headers({ "content-type": "application/json" }),
6260
extensions: null,
63-
// deno-lint-ignore no-explicit-any
64-
data: <T = any>(): T | null => ({ user: { name: "Alice" } }) as T,
61+
data: { user: { name: "Alice" } },
6562
duration: 100,
66-
raw: () =>
67-
new Response('{"data":{"user":{"name":"Alice"}}}', {
68-
status: 200,
69-
headers: { "content-type": "application/json" },
70-
}),
63+
raw: new Response('{"data":{"user":{"name":"Alice"}}}', {
64+
status: 200,
65+
headers: { "content-type": "application/json" },
66+
}),
7167
};
7268
return response;
7369
}

0 commit comments

Comments
 (0)