Created
February 11, 2026 18:47
-
-
Save claudiainbytes/96c29d175a38c7ef8f23f044c1ba7a68 to your computer and use it in GitHub Desktop.
Testing con React Router
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { MemoryRouter, Routes, Route } from 'react-router-dom' | |
| const renderWithRouter = (ui, { route = '/' } = {}) => { | |
| return render( | |
| <MemoryRouter initialEntries={[route]}> | |
| <Routes> | |
| <Route path="/" element={<Home />} /> | |
| <Route path="/products/:id" element={<ProductDetail />} /> | |
| <Route path="/cart" element={<Cart />} /> | |
| </Routes> | |
| </MemoryRouter> | |
| ) | |
| } | |
| describe('Navigation Flow', () => { | |
| it('navega de home a producto y al carrito', async () => { | |
| const user = userEvent.setup() | |
| renderWithRouter(<App />) | |
| // Click en producto | |
| const productLink = screen.getByRole('link', { name: /view product/i }) | |
| await user.click(productLink) | |
| // Verifica que está en la página de detalle | |
| expect(screen.getByRole('heading', { name: /product details/i })).toBeInTheDocument() | |
| // Agregar al carrito y navegar | |
| await user.click(screen.getByRole('button', { name: /add to cart/i })) | |
| const cartLink = screen.getByRole('link', { name: /cart/i }) | |
| await user.click(cartLink) | |
| // Verifica que está en el carrito | |
| expect(screen.getByRole('heading', { name: /shopping cart/i })).toBeInTheDocument() | |
| }) | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment