Skip to content

Commit c95699d

Browse files
committed
Add a test to verify Request parameter is used
1 parent bf4621a commit c95699d

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

packages/openapi-fetch/test/common/request.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,30 @@ describe("request", () => {
316316
await client.GET("/resources");
317317
});
318318

319+
describe("custom Request", () => {
320+
const ALL_METHODS = [["GET"], ["HEAD"], ["PUT"], ["POST"], ["DELETE"], ["OPTIONS"], ["PATCH"]] as const;
321+
322+
test.each(ALL_METHODS)("uses custom Request class - %s", async (method) => {
323+
// sanity check to make sure the provided fetch function is actually called
324+
expect.assertions(1);
325+
326+
class SpecialRequestImplementation extends Request { }
327+
328+
const customFetch = async (input: Request) => {
329+
// make sure that the request is actually an instance of the custom request we provided
330+
expect(input).instanceOf(SpecialRequestImplementation);
331+
return Promise.resolve(Response.json({ hello: "world" }));
332+
};
333+
334+
const client = createClient<paths>({
335+
baseUrl: "https://fakeurl.example",
336+
fetch: customFetch,
337+
});
338+
339+
await (client as any)[method]("/resources", { Request: SpecialRequestImplementation });
340+
});
341+
});
342+
319343
test("can attach custom properties to request", async () => {
320344
function createCustomFetch(data: any) {
321345
const response = {

0 commit comments

Comments
 (0)