feat: add support for optional dynamic route params (#1706)

This commit is contained in:
Michael Herzner
2023-09-07 14:28:44 +02:00
committed by GitHub
parent cda20720dd
commit 8a0d0dc452
6 changed files with 179 additions and 108 deletions
+20
View File
@@ -217,6 +217,26 @@ Deno.test("/books/:id page - /books/abc", async () => {
assertEquals(resp.status, Status.NotFound);
});
Deno.test("/i18n{/:lang}?/lang page - /i18n/lang", async () => {
const resp = await handler(new Request("https://fresh.deno.dev/i18n/lang"));
assert(resp);
assertEquals(resp.status, Status.OK);
assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8");
const body = await resp.text();
assertStringIncludes(body, "<div>Hello</div>");
});
Deno.test("/i18n{/:lang}?/lang page - /i18n/en/lang", async () => {
const resp = await handler(
new Request("https://fresh.deno.dev/i18n/en/lang"),
);
assert(resp);
assertEquals(resp.status, Status.OK);
assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8");
const body = await resp.text();
assertStringIncludes(body, "<div>Hello en</div>");
});
Deno.test("redirect /pages/fresh/ to /pages/fresh", async () => {
const resp = await handler(
new Request("https://fresh.deno.dev/pages/fresh/"),