Skip to content

Commit

Permalink
fix: getType is a function on route
Browse files Browse the repository at this point in the history
  • Loading branch information
rudionrails committed Oct 8, 2020
1 parent 8a361bd commit 889c5c8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ function createRoute(route) {
(acc, [key, value]) => acc.replace(new RegExp(`:${key}`, "g"), value),
route
);
routeFn.getType = route;

routeFn.getType = () => route;
routeFn.toString = () => route;

return routeFn;
}
Expand Down
8 changes: 6 additions & 2 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ test("to return nested route, e.g. people/:id/tasks/:taskId", t => {
);
});

test("to set computed property (set getType)", t => {
test("to set getType property", t => {
const routes = createRoutes({ tasks: "/tasks/:id" });
t.is("/tasks/:id", routes.tasksPath.getType());
});

t.is("/tasks/:id", routes.tasksPath.getType);
test("to set toString property", t => {
const routes = createRoutes({ tasks: "/tasks/:id" });
t.is("/tasks/:id", routes.tasksPath.toString());
});

0 comments on commit 889c5c8

Please # to comment.