Testing with Jest
Jest is a widely adopted open source JavaScript testing framework developed by Facebook. It is particularly favored for testing React applications, though its versatility extends to Node.js environments. Jest is an opinionated testing framework with a host of bundled features.
In this guide, we will explore how to effectively write and structure tests using Jest. You’ll learn the key principles of Jest and how to set up your testing environment. Additionally, we’ll explore Jest’s capabilities in measuring and reporting test coverage to help you understand how well your code base is covered by tests.
Getting ready
We will be using Jest to test a program that provides some text utility functions.
- First, let’s create and initialize our project directory:
$ mkdir testing-with-jest $ cd testing-with-jest $ npm init --yes
- We need a program to test. Create a file named
textUtils.js
:$ touch textUtils.js
- Add the following code...