6. Testing Express/Connect-based applications

Jest is great to test Express/Connect-based applications.

In this section you will learn to:

  • use mock request and response objects to test express route handlers and middleware
  • use supertest to test express routing, route handlers and middleware

There are 2 approaches to testing Express/Connect applications in JavaScript with Jest.

The first involves testing only the request handlers by passing mock request and response objects.

The other leverages supertest to write test in-memory (no issues with port allocations), but with what’s essentially a full Express application, using supertest.

Jump to table of contents