# Testing Routes — Express.js Fundamentals: Routing, Middleware and APIs

Source: https://www.skillbyai.com/en/expressjs/ex-testing

> Test Express routes in-process with supertest by exporting the app without calling listen.

## Exercise the HTTP layer

**supertest** wraps your Express `app` and lets tests fire real HTTP requests at it — no need to actually bind a port.

## A supertest example

Export `app` without calling `listen()` in it, so tests import it directly.

```javascript
import request from 'supertest';
import app from '../app.js';

test('GET /health returns ok', async () => {
  const res = await request(app).get('/health');
  expect(res.status).toBe(200);
  expect(res.body.status).toBe('ok');
});
```
