Home > Software engineering >  Testing back button using react router and react testing library
Testing back button using react router and react testing library

Time:05-12

I have a component which allows users to navigate back in history using react router v6's useNavigate hook. However, the test seems to fail when I call the function with navigate(-1) but passes if I pass a string url eg. navigate("/home"). Does anyone know the right way to test navigate(-1)? Here's a codesandbox to illustrate the issue Edit testing-back-button-using-react-router-and-react-testing-library

CodePudding user response:

<button onClick={() => navigate(-1)}>go back</button>
  • Related