Skip to content

Commit 4de96c4

Browse files
committed
added unit test
1 parent fa2ee89 commit 4de96c4

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

packages/openapi-fetch/test/index.test.ts

+30-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
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";
38
import type { paths } from "./fixtures/api.js";
49
import { server, baseUrl, useMockRequestHandler, toAbsoluteURL } from "./fixtures/mock-server.js";
510

@@ -854,6 +859,29 @@ describe("client", () => {
854859
expect(req.headers.get("foo")).toBe("bar");
855860
});
856861

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+
857885
it("can modify response", async () => {
858886
const toUnix = (date: string) => new Date(date).getTime();
859887

0 commit comments

Comments
 (0)