Mocking React Router’s match object in component unit tests

Adam J. Arling
2 min readSep 24, 2019

Recently our UI team has switched from Enzyme to Kent Dodd’s Testing Library for a much improved, simplified experience in testing JavaScript and React components.

The issue
We have a growing number of applications which rely upon React Router to to handle client-side routing, and a good number of “container” components are dependent upon a URL parameter value for making network requests.

When testing these components with Testing Library / Jest, we need a way to mock routes and…

--

--

Adam J. Arling

Front End Developer who enjoys creating exceptional user experiences using JavaScript, React, TypeScript, NextJS, and API-driven development.