E2E testing
While unit tests are isolated and independent by definition, end-to-end (or E2E) tests serve for, in a way, the opposite function: they intend to check the health of the system as a whole, and try to include as many components of the solution as possible. For this reason, in E2E tests we will focus on testing complete modules, rather than isolated components or controllers.
Preparation
Fortunately, we can use Jest for E2E testing just like we did for unit testing. We will only need to install the supertest
npm package to perform API requests and assert their result. Let’s install it by running npm install --save-dev supertest
in your console.
Also, we will create a folder called e2e
in our project’s root folder. This folder will hold all of our E2E test files, as well as the configuration file for them.
This brings us to the next step: create a new jest-e2e.json
file inside the e2e
folder with the following contents:
{
"moduleFileExtensions"
:
...