Tag: react

How to test redirections and history state with Jest

crysfel Programming

Testing redirections in jest using react router is not a straight forward process, specially when using hooks. In this tutorial I'm going to show you how to test a redirect, in addition we are going to test the state in the history. The code we will be testing is a button, when clicked we will redirect the user to a new page using react router, but we are also going to set some data into the history state. import React from 'react'; import { useNavigate, useLocation } from 'react-router-dom'; Continue reading