From b15946b6d34b992e45e69c6274541d60b499d971 Mon Sep 17 00:00:00 2001 From: Manuel Schiller Date: Thu, 3 Oct 2024 17:35:47 +0200 Subject: [PATCH 1/2] tests: reproducer for #2450 --- packages/react-router/tests/router.test.tsx | 29 +++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/packages/react-router/tests/router.test.tsx b/packages/react-router/tests/router.test.tsx index 29ebd08b77..005700ce7d 100644 --- a/packages/react-router/tests/router.test.tsx +++ b/packages/react-router/tests/router.test.tsx @@ -7,6 +7,7 @@ import { screen, waitFor, } from '@testing-library/react' +import { z } from 'zod' import { Link, Outlet, @@ -74,6 +75,17 @@ function createTestRouter(initialHistory?: RouterHistory) { path: '$', }) + const routeWithParamsParseStringify = createRoute({ + getParentRoute: () => rootRoute, + path: '/paramsParseStringify/$id', + params: { + parse: (params) => ({ + id: z.number().int().parse(Number(params.id)), + }), + stringify: ({ id }) => ({ id: `${id}` }), + }, + }) + const routeTree = rootRoute.addChildren([ indexRoute, postsRoute.addChildren([postIdRoute]), @@ -85,6 +97,7 @@ function createTestRouter(initialHistory?: RouterHistory) { pathSegmentLayoutSplatIndexRoute, pathSegmentLayoutSplatSplatRoute, ]), + routeWithParamsParseStringify, ]) const router = createRouter({ routeTree, history }) @@ -580,3 +593,19 @@ describe('router matches URLs to route definitions', () => { ]) }) }) + + +describe('matchRoute', () => { + it('should match route with custom parse/stringify functions', async () => { + + const { router } = createTestRouter( + createMemoryHistory({ + initialEntries: ['/paramsParseStringify/123'], + }), + ) + await act(() => router.load()) + const result = router.matchRoute({to: '/paramsParseStringify/$id', params: { id: 123 }}) + expect(result).toBeTruthy(); + expect((result as any).id).toBe(123); + }) +}) \ No newline at end of file From ed5a455fea13cb5b4f4fa1fdb7085b07d64c02ed Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Thu, 3 Oct 2024 15:37:17 +0000 Subject: [PATCH 2/2] ci: apply automated fixes --- packages/react-router/tests/router.test.tsx | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/react-router/tests/router.test.tsx b/packages/react-router/tests/router.test.tsx index 005700ce7d..cecd8f7a17 100644 --- a/packages/react-router/tests/router.test.tsx +++ b/packages/react-router/tests/router.test.tsx @@ -594,18 +594,19 @@ describe('router matches URLs to route definitions', () => { }) }) - describe('matchRoute', () => { it('should match route with custom parse/stringify functions', async () => { - const { router } = createTestRouter( createMemoryHistory({ initialEntries: ['/paramsParseStringify/123'], }), ) await act(() => router.load()) - const result = router.matchRoute({to: '/paramsParseStringify/$id', params: { id: 123 }}) - expect(result).toBeTruthy(); - expect((result as any).id).toBe(123); + const result = router.matchRoute({ + to: '/paramsParseStringify/$id', + params: { id: 123 }, + }) + expect(result).toBeTruthy() + expect((result as any).id).toBe(123) }) -}) \ No newline at end of file +})