1. Chapters
  2. How to make testing a habit

Master useEffect in a single afternoon - 50% off!
2 days 11 hours 1 mins 8 secs

Chapters

How to make testing a habit

Use feedback loops

My favourite part of testing in React is the feedback loop I get from running Jest in watch mode. By passing Jest the --watch flag (so yarn test --watch), I'm able to have jest only run tests for files that I change, and in doing so, I know in the moment when I've broken something.

You might have a huge React app with hundreds of tests - in that case you'll want to tell your test runner to only watch the file you're modifying.

Run all of your tests as part of CI

This assumes your team's project uses CI (which it should), but running all of your tests - both on the branch you're working on, and the main branch helps ensure your code works as you expect before deploying.

You might be wondering how this helps build a testing habit - the trick is, you won't be able to deliver code if your tests aren't passing, so it forces you to run tests as you code.


Next, let's look at coverage in Chapter 6: What's a good level of code coverage?

Want more articles like this?

I send a single email every two weeks with an article like this one, to help you be a better React developer.

Lots of developers like them, and I'd love to hear what you think as well. You can always unsubscribe.

    Join 910 React developers that have signed up so far.
    See my privacy policy.