-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_route_test.ts
50 lines (42 loc) · 1.24 KB
/
_route_test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
import createRoute from "./_route.ts";
import { pathToRegexp } from "./deps.ts";
Deno.test("basicRouteObject", () => {
const { params, ...route } = createRoute("GET", "/", "/routes/index.get.ts");
assertEquals(route, {
filePath: "/routes/index.get.ts",
path: "/",
method: "GET",
regexp: pathToRegexp.pathToRegexp("/"),
});
});
Deno.test("nonEndingRouteObject", () => {
const { params, ...route } = createRoute("GET", "/*", "/routes/_hook.ts");
assertEquals(route, {
filePath: "/routes/_hook.ts",
path: "/*",
method: "GET",
regexp: pathToRegexp.pathToRegexp("/", [], {
end: false,
}),
});
});
Deno.test("routeParams", () => {
const { params } = createRoute(
"GET",
"/[first]-[last]/comments/[comment]/view",
"./routes/[first]-[last]/comments/[comment]/view.get.ts",
);
assertEquals(
params("/chris-turner/comments/123/view"),
new Map([["first", "chris"], ["last", "turner"], ["comment", "123"]]),
);
});
Deno.test("routeParamsNone", () => {
const { params } = createRoute(
"GET",
"/profile/[name]",
"./routes/profile/[name].get.ts",
);
assertEquals(params("/does/not/match"), new Map());
});