diff --git a/src/utils/add-route.ts b/src/utils/add-route.ts index d43f87b0..baca878f 100644 --- a/src/utils/add-route.ts +++ b/src/utils/add-route.ts @@ -15,8 +15,8 @@ export default (router: any, route: Route, opts?: any): void => { } endpoint.path = endpoint.path.map((p: string): string => { - const { name } = parse(p); - return join('/', name); + const { name, dir } = parse(p); + return join('/', dir, name); }); // if the path is /index, map it to the root route as well diff --git a/tests/utils/add-route.ts b/tests/utils/add-route.ts index 6b41b5d2..558a7fd2 100644 --- a/tests/utils/add-route.ts +++ b/tests/utils/add-route.ts @@ -98,5 +98,24 @@ describe('utils', () => { expect(router.on).toHaveBeenCalledWith(['GET'], '/', expect.any(Function)); }); }); + + describe('with nested route', () => { + const router = { + on: jest.fn(), + }; + + const route = { + path: '/multi/level', + method: 'GET', + handler: jest.fn(), + }; + + it('adds the nested route', async () => { + expect.assertions(2); + addRoute(router, route); + expect(router.on.mock.calls.length).toBe(1); + expect(router.on).toHaveBeenCalledWith(['GET'], '/multi/level', expect.any(Function)); + }); + }); }); });