fix: write matched pattern into ctx.route (#3113)

Fixes https://github.com/denoland/fresh/issues/3112
This commit is contained in:
Marvin Hagemeister
2025-07-18 22:38:56 +02:00
committed by GitHub
parent 83da608504
commit 39737b4530
5 changed files with 41 additions and 0 deletions
+22
View File
@@ -84,3 +84,25 @@ Deno.test("ctx.isPartial - should indicate whether request is partial or not", a
expect(isPartials).toEqual([false, true]);
});
Deno.test("ctx.route - should contain matched route", async () => {
let route: string | null = null;
const app = new App()
.use((ctx) => {
route = ctx.route;
return ctx.next();
})
.get("/foo/bar", () => new Response("ok"))
.get("/foo/:id", () => new Response("ok"));
const server = new FakeServer(app.handler());
await server.get("/invalid");
expect(route).toEqual(null);
await server.get("/foo/bar");
expect(route).toEqual("/foo/bar");
await server.get("/foo/123");
expect(route).toEqual("/foo/:id");
});