Skip to content

Commit 3437a24

Browse files
committed
Add type test for middleware
1 parent 200d5d2 commit 3437a24

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { expect, test } from "vitest";
1+
import { expect, test, expectTypeOf, assertType } from "vitest";
22
import { createObservedClient } from "../helpers.js";
33
import type { Middleware, MiddlewareCallbackParams } from "../../src/index.js";
44
import type { paths } from "./schemas/middleware.js";
@@ -354,3 +354,12 @@ test("auth header", async () => {
354354
});
355355
expect(headers.get("authorization")).toBe(`Bearer ${accessToken}`);
356356
});
357+
358+
test("type error occurs only when neither onRequest nor onResponse is specified", async () => {
359+
expectTypeOf<Middleware>().not.toEqualTypeOf({});
360+
const onRequest = async ({ request }: MiddlewareCallbackParams) => request;
361+
const onResponse = async ({ response }: MiddlewareCallbackParams & { response: Response }) => response;
362+
assertType<Middleware>({ onRequest });
363+
assertType<Middleware>({ onResponse });
364+
assertType<Middleware>({ onRequest, onResponse });
365+
});

0 commit comments

Comments
 (0)