# Testing Routes — Express.js

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

> supertest drives real requests against your app in-process.

## 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');
});
```
