fix: write matched pattern into ctx.route (#3113)
Fixes https://github.com/denoland/fresh/issues/3112
This commit is contained in:
@@ -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");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user