Recharts

Learn how to properly mock Recharts—a popular charting library for the browser.

Why do we mock Recharts?

The Recharts package is a wonderful library that makes it simple to create and render beautiful data charts to our clients. While this is an extremely useful tool to have, these types of client-side, render-focused libraries can cause issues in testing. Much of what makes them so easy to use and so nice for the user—animated loading, resizing with the window, and chart interaction—is reliant on the browser environment. It may run fine in a test environment, or its pain points may present themselves in seemingly random errors that are difficult to trace and debug. Since the rendering of a chart is not required for the types of tests we are dealing with in this course, it’s best to mock the functionality.

Get hands-on with 1400+ tech skills courses.