MCPcopy
hub / github.com/TanStack/router / runTest

Function runTest

packages/solid-router/tests/useNavigate.test.tsx:1328–1471  ·  view source on GitHub ↗
(navigateVia: 'Route' | 'RouteApi')

Source from the content-addressed store, hash-verified

1326
1327describe('when on /posts/$postId and navigating to ../ with default `from` /posts', () => {
1328 async function runTest(navigateVia: 'Route' | 'RouteApi') {
1329 const rootRoute = createRootRoute()
1330
1331 const IndexComponent = () => {
1332 const navigate = useNavigate()
1333 return (
1334 <>
1335 <h1 data-testid="index-heading">Index</h1>
1336 <button onClick={() => navigate({ to: '/posts' })}>Posts</button>
1337 <button
1338 data-testid="index-to-first-post-btn"
1339 onClick={() =>
1340 navigate({
1341 to: '/posts/$postId/details',
1342 params: { postId: 'id1' },
1343 })
1344 }
1345 >
1346 To first post
1347 </button>
1348 </>
1349 )
1350 }
1351
1352 const indexRoute = createRoute({
1353 getParentRoute: () => rootRoute,
1354 path: '/',
1355 component: IndexComponent,
1356 })
1357
1358 const layoutRoute = createRoute({
1359 getParentRoute: () => rootRoute,
1360 id: '_layout',
1361 component: () => {
1362 return (
1363 <>
1364 <h1>Layout</h1>
1365 <Outlet />
1366 </>
1367 )
1368 },
1369 })
1370
1371 const PostsComponent = () => {
1372 const routeNavigate = postsRoute.useNavigate()
1373 const routeApiNavigate = getRouteApi('/_layout/posts').useNavigate()
1374 return (
1375 <>
1376 <h1>Posts</h1>
1377 <button
1378 data-testid="btn-to-home"
1379 onClick={() => {
1380 if (navigateVia === 'Route') {
1381 routeNavigate({ to: '../' })
1382 } else {
1383 routeApiNavigate({ to: '../' })
1384 }
1385 }}

Callers 1

Calls 4

createRootRouteFunction · 0.90
createRouteFunction · 0.90
createRouterFunction · 0.90
renderFunction · 0.50

Tested by

no test coverage detected