|
6 | 6 | matchRoutes,
|
7 | 7 | MemoryRouter,
|
8 | 8 | Navigate,
|
| 9 | + Outlet, |
9 | 10 | Route,
|
10 | 11 | Routes,
|
11 | 12 | useLocation,
|
@@ -525,5 +526,96 @@ describe('React Router v6', () => {
|
525 | 526 | metadata: { source: 'route' },
|
526 | 527 | });
|
527 | 528 | });
|
| 529 | + |
| 530 | + it('does not add double slashes to URLS', () => { |
| 531 | + const [mockStartTransaction, { mockSetName }] = createInstrumentation(); |
| 532 | + const wrappedUseRoutes = wrapUseRoutes(useRoutes); |
| 533 | + |
| 534 | + const Routes = () => |
| 535 | + wrappedUseRoutes([ |
| 536 | + { |
| 537 | + path: '/', |
| 538 | + element: ( |
| 539 | + <div> |
| 540 | + <Outlet /> |
| 541 | + </div> |
| 542 | + ), |
| 543 | + children: [ |
| 544 | + { |
| 545 | + path: 'tests', |
| 546 | + children: [ |
| 547 | + { index: true, element: <div>Main Test</div> }, |
| 548 | + { path: ':testId/*', element: <div>Test Component</div> }, |
| 549 | + ], |
| 550 | + }, |
| 551 | + { path: '/', element: <Navigate to="/home" /> }, |
| 552 | + { path: '*', element: <Navigate to="/404" replace /> }, |
| 553 | + ], |
| 554 | + }, |
| 555 | + { |
| 556 | + path: '/', |
| 557 | + element: <div />, |
| 558 | + children: [ |
| 559 | + { path: '404', element: <div>Error</div> }, |
| 560 | + { path: '*', element: <Navigate to="/404" replace /> }, |
| 561 | + ], |
| 562 | + }, |
| 563 | + ]); |
| 564 | + |
| 565 | + render( |
| 566 | + <MemoryRouter initialEntries={['/tests']}> |
| 567 | + <Routes /> |
| 568 | + </MemoryRouter>, |
| 569 | + ); |
| 570 | + |
| 571 | + expect(mockStartTransaction).toHaveBeenCalledTimes(1); |
| 572 | + // should be /tests not //tests |
| 573 | + expect(mockSetName).toHaveBeenLastCalledWith('/tests', 'route'); |
| 574 | + }); |
| 575 | + |
| 576 | + it('handles wildcard routes properly', () => { |
| 577 | + const [mockStartTransaction, { mockSetName }] = createInstrumentation(); |
| 578 | + const wrappedUseRoutes = wrapUseRoutes(useRoutes); |
| 579 | + |
| 580 | + const Routes = () => |
| 581 | + wrappedUseRoutes([ |
| 582 | + { |
| 583 | + path: '/', |
| 584 | + element: ( |
| 585 | + <div> |
| 586 | + <Outlet /> |
| 587 | + </div> |
| 588 | + ), |
| 589 | + children: [ |
| 590 | + { |
| 591 | + path: 'tests', |
| 592 | + children: [ |
| 593 | + { index: true, element: <div>Main Test</div> }, |
| 594 | + { path: ':testId/*', element: <div>Test Component</div> }, |
| 595 | + ], |
| 596 | + }, |
| 597 | + { path: '/', element: <Navigate to="/home" /> }, |
| 598 | + { path: '*', element: <Navigate to="/404" replace /> }, |
| 599 | + ], |
| 600 | + }, |
| 601 | + { |
| 602 | + path: '/', |
| 603 | + element: <div />, |
| 604 | + children: [ |
| 605 | + { path: '404', element: <div>Error</div> }, |
| 606 | + { path: '*', element: <Navigate to="/404" replace /> }, |
| 607 | + ], |
| 608 | + }, |
| 609 | + ]); |
| 610 | + |
| 611 | + render( |
| 612 | + <MemoryRouter initialEntries={['/tests/123']}> |
| 613 | + <Routes /> |
| 614 | + </MemoryRouter>, |
| 615 | + ); |
| 616 | + |
| 617 | + expect(mockStartTransaction).toHaveBeenCalledTimes(1); |
| 618 | + expect(mockSetName).toHaveBeenLastCalledWith('/tests/:testId/*', 'route'); |
| 619 | + }); |
528 | 620 | });
|
529 | 621 | });
|
0 commit comments