From 889c5c8db7c7674521d2c9010c7e16cbf53f0adf Mon Sep 17 00:00:00 2001 From: Rudolf Schmidt Date: Thu, 8 Oct 2020 16:26:46 +0200 Subject: [PATCH] fix: getType is a function on route --- index.js | 4 +++- index.test.js | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index fc99c1d..5bc45e9 100644 --- a/index.js +++ b/index.js @@ -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; } diff --git a/index.test.js b/index.test.js index fb50e1a..ebbe0c1 100644 --- a/index.test.js +++ b/index.test.js @@ -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()); });