Member-only story

React Testing Library: Writing Tests for Noobs

Brian Jenney
3 min readSep 21, 2020

--

Developers laughing around a desk
Testing? Isn’t that what end users are for?

You know you’re supposed to be writing tests. You know this. If you’re a developer using React on the front end and using CRA to bootstrap your application then your app ships with testing-library, React’s suggested testing framework. Now, all you have to do is write some tests!

If you are completely new to writing tests, any testing framework can be daunting. It can seem like you’re about to double your efforts for each feature you want to ship and now you have the additional cognitive load of understanding the nuances of a testing framework. The testing-library docs leave a lot to be desired in my opinion. I would love to see more real-world examples, but luckily its popularity has made googling any common use case trivial.

So here you are, filled to the brim with excitement about the badass test you’re about to write for your ProductDetail component. It’s a simple enough component that uses some redux state and context value to render a card with the name of the product and the number of items in a user’s cart.

--

--

Brian Jenney
Brian Jenney

Written by Brian Jenney

full-stackish developer, late bloomer coder and power google user and owner of Parsity.io

No responses yet