BlogMesh
Post
Dec 13, 2021

React Testing

You can test React components similar to testing other JavaScript code.

There are a few ways to test React components. Broadly, they divide into two categories:

This documentation section focuses on testing strategies for the first case. While full end-to-end tests can be very useful to prevent regressions to important workflows, such tests are not concerned with React components in particular, and are out of the scope of this section.

Tradeoffs

When choosing testing tools, it is worth considering a few tradeoffs:

Different answers may work for different teams and products.

Recommended Tools

is a JavaScript test runner that lets you access the DOM via . While jsdom is only an approximation of how the browser works, it is often good enough for testing React components. Jest provides a great iteration speed combined with powerful features like mocking and so you can have more control over how the code executes.

is a set of helpers that let you test React components without relying on their implementation details. This approach makes refactoring a breeze and also nudges you towards best practices for accessibility. Although it doesn’t provide a way to “shallowly” render a component without its children, a test runner like Jest lets you do this by .

Learn More

This section is divided in two pages:

Aryan Garg

Author: Aryan Garg

About Author: Aryan Loves Many Things Around The World

Leave A Comment

Related Posts

Categories

Created By © ARYAN GARG @2021