Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

431
Views
¿Cómo probar un enlace de enrutador de reacción con la biblioteca de prueba?

Quiero probar un enlace de enrutador de reacción con la biblioteca de prueba, probé:

Aplicación.js:

 import React from 'react' import { Routes, NavLink, Route } from 'react-router-dom' function App() { return ( <div> <nav> <NavLink to={"/"}>Home</NavLink> <NavLink to={"/about"}>About</NavLink> </nav> <Routes> <Route path="/" element="home page" /> <Route path="/about" element="about page" /> </Routes> </div> ) } export default App

Aplicación.prueba.js:

 import { render, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { createMemoryHistory } from 'history'; import { Route, Router } from "react-router-dom" import App from './App'; test('first home link', () => { const history = createMemoryHistory({ initialEntries: ["/"] }); render( <Router location={history.location} navigator={history}> <App /> </Router> ); const linkElement = screen.getByRole("link", { name: /about/i }); userEvent.click(linkElement); screen.debug(); });

Salida de screen.debug:

 <body> <div> <div> <nav> <a aria-current="page" class="active" href="/" > Home </a> <a class="" href="/about" > About </a> </nav> home page </div> </div> </body>

la página no cambió a acerca de la página como se ve en la salida de la pantalla. depuración

¿Hay alguna manera de arreglar eso?

dependencias:

  1. "@testing-library/jest-dom": "^5.16.4"
  2. "@testing-library/react": "^13.3.0"
  3. "@testing-library/user-event": "^13.5.0"
  4. "historia": "^5.3.0"
  5. "reaccionar": "^18.1.0"
  6. "reaccionar-router-dom": "^6.3.0"
  7. "reaccionar-dom": "^18.1.0"
about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!