|
| 1 | +import { describe, expectTypeOf, it } from "vitest"; |
| 2 | +import type { InferParam } from "./context"; |
| 3 | +import type { InferParamPath, InferParamWildCard } from "./helper"; |
| 4 | + |
| 5 | +describe("infer param", () => { |
| 6 | + it("empty path", () => { |
| 7 | + expectTypeOf<InferParamPath<"/">>().toEqualTypeOf<{}>(); |
| 8 | + expectTypeOf<InferParamWildCard<"/">>().toEqualTypeOf<{}>(); |
| 9 | + expectTypeOf<InferParam<"/">>().toEqualTypeOf<{}>(); |
| 10 | + }); |
| 11 | + it("static path", () => { |
| 12 | + expectTypeOf<InferParamPath<"/static/path">>().toEqualTypeOf<{}>(); |
| 13 | + expectTypeOf<InferParamWildCard<"/static/path">>().toEqualTypeOf<{}>(); |
| 14 | + expectTypeOf<InferParam<"/static/path">>().toEqualTypeOf<{}>(); |
| 15 | + }); |
| 16 | + it("single param", () => { |
| 17 | + expectTypeOf<InferParamPath<"/user/:id">>().toEqualTypeOf<{ id: string }>(); |
| 18 | + expectTypeOf<InferParamWildCard<"/user/:id">>().toEqualTypeOf<{}>(); |
| 19 | + expectTypeOf<InferParam<"/user/:id">>().toEqualTypeOf<{ id: string }>(); |
| 20 | + }); |
| 21 | + it("multiple params", () => { |
| 22 | + expectTypeOf<InferParamPath<"/user/:userId/post/:postId">>().toEqualTypeOf<{ |
| 23 | + userId: string; |
| 24 | + postId: string; |
| 25 | + }>(); |
| 26 | + expectTypeOf<InferParamWildCard<"/user/:userId/post/:postId">>().toEqualTypeOf<{}>(); |
| 27 | + expectTypeOf<InferParam<"/user/:userId/post/:postId">>().toEqualTypeOf<{ |
| 28 | + userId: string; |
| 29 | + postId: string; |
| 30 | + }>(); |
| 31 | + }); |
| 32 | + it("wildcard param", () => { |
| 33 | + expectTypeOf<InferParamPath<"/files/*">>().toEqualTypeOf<{}>(); |
| 34 | + expectTypeOf<InferParamWildCard<"/files/*">>().toEqualTypeOf<{ _: string }>(); |
| 35 | + expectTypeOf<InferParam<"/files/*">>().toEqualTypeOf<{ _: string }>(); |
| 36 | + }); |
| 37 | + it("mixed params", () => { |
| 38 | + expectTypeOf<InferParamPath<"/user/:userId/files/*">>().toEqualTypeOf<{ userId: string }>(); |
| 39 | + expectTypeOf<InferParamWildCard<"/user/:userId/files/*">>().toEqualTypeOf<{ _: string }>(); |
| 40 | + expectTypeOf<InferParam<"/user/:userId/files/*">>().toEqualTypeOf<{ |
| 41 | + userId: string; |
| 42 | + _: string; |
| 43 | + }>(); |
| 44 | + }); |
| 45 | +}); |
0 commit comments