Skip to content

Commit fbedfe0

Browse files
committed
Add a test to verify Request parameter is used
1 parent 15112b9 commit fbedfe0

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

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

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

319+
test("Can use custom Request class", async () => {
320+
// sanity check to make sure the provided fetch function is actually called
321+
expect.assertions(1);
322+
323+
class SpecialRequestImplementation extends Request {}
324+
325+
const customFetch = async (input: Request) => {
326+
// make sure that the request is actually an instance of the custom request we provided
327+
expect(input).instanceOf(SpecialRequestImplementation);
328+
return Promise.resolve(Response.json({ hello: "world" }));
329+
};
330+
331+
const client = createClient<paths>({
332+
baseUrl: "https://fakeurl.example",
333+
fetch: customFetch,
334+
});
335+
336+
await client.GET("/resources", { Request: SpecialRequestImplementation });
337+
});
338+
319339
test("can attach custom properties to request", async () => {
320340
function createCustomFetch(data: any) {
321341
const response = {

0 commit comments

Comments
 (0)