Creating integration tests for Express REST APIs
The next level of testing abstraction is integration tests. Unlike unit tests, which rely on only mocks to derive their behavior, integration tests usually introduce some level of real application integration with other services, connections, and dependencies. These tests can be highly important as they can be much more behaviorally realistic in their definition than unit tests. They are excellent for testing full behaviors of your application while still being very focused on individual parts. Testing functionalities such as our Express REST APIs and checking their expected results make for great integration tests.
Getting ready
Let's explore how to add some API integration tests to our Express web server's REST API. In order to work with our API, we'll need to install a Chai plugin called chai-http
, which will work as a lightweight request library to make HTTP
request assertions in our tests:
npm install chai-http @types/chai-http --save-dev...