When I first started writing unit tests with a real unit testing framework, there was little documentation, and the frameworks I worked with didn’t have proper examples. (I was mostly coding in VB 5 and 6 at the time.) It was a challenge learning to work with them, and I started out writing rather poor tests. Fortunately, times have changed. In JavaScript, and in practically any language out there, there’s a wide range of choices and plenty of documentation and support from the community for trying out these bundles of helpfulness.
In the previous chapter, we wrote a very simple home-grown test framework. In this chapter, we’ll take a look at Jest, which will be our framework of choice for this book.
Jest is an open source test framework created by Facebook. It’s easy to use, easy to remember, and has lots of great features. Jest was originally created for testing frontend React components in JavaScript. These days it’s widely used in many parts of the industry for both backend and frontend project testing. It supports two major flavors of test syntax (one that uses the word test and another that’s based on the Jasmin syntax, a framework that has inspired many of Jest’s features). We’ll try both of them to see which one we like better.