Unit Testing Your React Application

By Steven Hicks

Elevator Pitch

This session will introduce you to the tools Jest and React Testing Library, and show how you can use them to write meaningful and maintainable unit tests for a React app. You’ll learn what to test and how to test it, from basics to best practices. Attendees will leave empowered to test confidently.

Description

Writing unit tests is like making good food choices. We know it’s beneficial to us, and it’s easy to do when we aren’t stressed. But give us a looming deadline and a product owner looking over our shoulder, and we throw our good habits out the window.

React testing tools can help you maintain good unit testing habits. Setup with Jest as a test-runner and test framework is a breeze. React Testing Library enables you to write simple tests of your React components, with clear intentions. In this session, you’ll learn how to use these tools to write meaningful and maintainable unit tests.

We’ll also talk about guidance and best practices. What should you test? When should you test it? How can you keep your React code friendly to tests?

This session will arm you with the tools and guidance to unit test your React app. You’ll leave ready to write tests!

Notes

Unit testing is often the first thing to get dropped or skipped in a project. It seems like this is especially true with front-end code. I believe this is because developers don’t realize how easy it is to test their JavaScript. This session is an opportunity to show React developers how easy it is to test their code, and introduce them to test tooling.

The talk is approachable for beginners, with each example building on the previous. The bulk of the talk is spent on the features of Jest and React Testing Library. The last section of the talk includes useful guidance for all levels, empowering attendees to start testing their app with confidence.

I have presented this talk at MidwestJS 2017 in Minneapolis, CodeMash 2018 in Ohio, Open Source North 2018 in Minnesota, and That Conference 2018 in Wisconsin. At CodeMash, I received an average rating of 4.9/5.0 from attendees.

Note: All links below reveal speaker information.

Slides: https://bit.ly/unit-testing-your-react-app

Some reactions from Twitter:

  • https://twitter.com/jayharris/status/951571351906799617
  • https://twitter.com/jayharris/status/951884756630822914
  • https://twitter.com/spetryjohnson/status/952177135841693696
  • https://twitter.com/psberres/status/951649356251320320
  • https://twitter.com/LaurenBeatty13/status/1007305001390178305