15.12.2021 |

React Testing Library - Encouraging better testing practices

In April 2018 Kent C. Dodds created a new testing library for React projects. It can be used with any test runner like jest, jasmine and such. It is described as "Simple and complete React DOM testing utilities that encourage good testing practices."

The problem according to Kent is that most people tend to include implementation details in their tests which makes it hard to maintain and make changes to the codebase without breaking every test and thus slowing down the development process.

Kent's solution is to hide the rendered component instance and only supply the tester with a small number of query methods. These methods only allow for querying actual DOM nodes and only how an actual user would "query" those. That means you can query for actual text content, labels, placeholders and A11y roles. This ensures that your component stays usable and it gives you confidence that your components work correctly when a real user uses it.

For a detailed introduction visit Kent's Blog

Zur Übersicht
Sven Röttering

Mehr vom Devsquad...

Dennis Hundertmark

Cypress Flaky tests – Dem Wahnsinn Einhalt gebieten

Sven Röttering

Webvitals 101

Hallo, ich bin Jörg Herbst!

Ich bin der CEO von newcubator und freue mich über jede Nachricht!

* Pflichtfeld