Explore Related Tools
Hand-picked utilities and calculators related to this tool.
Unlike unit tests, Integration Tests verify that your API routes, controllers, and database work together as a cohesive unit.
Supertest allows you to make HTTP requests to your app programmatically without actually starting the server on a network port.
const request = require('supertest');
const app = require('./app');
describe('GET /api/users', () => {
it('should return all users with 200 OK', async () => {
const res = await request(app).get('/api/users');
expect(res.statusCode).toEqual(200);
expect(res.body.status).toBe('success');
expect(Array.isArray(res.body.data.users)).toBe(true);
});
});You can chain headers (like Bearer tokens) to test protected routes.
const res = await request(app)
.post('/api/products')
.set('Authorization', 'Bearer ' + token)
.send({ name: 'iPhone', price: 999 });Never run tests against your production database. Use an in-memory database (like mongodb-memory-server) or a dedicated local Test DB that is cleared before each run.
Hand-picked utilities and calculators related to this tool.
