|
1 |
| -import { HttpResponse, type StrictResponse } from "msw"; |
2 |
| -import createClient, { type Middleware, type MiddlewareRequest, type QuerySerializerOptions } from "../src/index.js"; |
| 1 | +import { HttpResponse, type StrictRequest, type StrictResponse } from "msw"; |
| 2 | +import createClient, { |
| 3 | + type BodyType, |
| 4 | + type Middleware, |
| 5 | + type MiddlewareRequest, |
| 6 | + type QuerySerializerOptions, |
| 7 | +} from "../src/index.js"; |
3 | 8 | import type { paths } from "./fixtures/api.js";
|
4 | 9 | import { server, baseUrl, useMockRequestHandler, toAbsoluteURL } from "./fixtures/mock-server.js";
|
5 | 10 |
|
@@ -854,6 +859,29 @@ describe("client", () => {
|
854 | 859 | expect(req.headers.get("foo")).toBe("bar");
|
855 | 860 | });
|
856 | 861 |
|
| 862 | + it("can attach custom properties to request", async () => { |
| 863 | + function createCustomFetch(data: any) { |
| 864 | + const response = { |
| 865 | + clone: () => ({ ...response }), |
| 866 | + headers: new Headers(), |
| 867 | + json: async () => data, |
| 868 | + status: 200, |
| 869 | + ok: true, |
| 870 | + } as Response; |
| 871 | + return async (input: Request) => { |
| 872 | + expect(input).toHaveProperty("customProperty", "value"); |
| 873 | + return Promise.resolve(response); |
| 874 | + }; |
| 875 | + } |
| 876 | + |
| 877 | + const customFetch = createCustomFetch({}); |
| 878 | + const client = createClient<paths>({ fetch: customFetch, baseUrl }); |
| 879 | + |
| 880 | + client.GET("/self", { |
| 881 | + customProperty: "value", |
| 882 | + }); |
| 883 | + }); |
| 884 | + |
857 | 885 | it("can modify response", async () => {
|
858 | 886 | const toUnix = (date: string) => new Date(date).getTime();
|
859 | 887 |
|
|
0 commit comments