This is a simple boilerplate for building and testing APIs using Express.js, Jest, and Supertest.
src/ # Source code
app.js # Express app
routes/ # API routes
controllers/ # Route handlers
services/ # Business logic
tests/ # All tests
integration/ # API endpoint tests
unit/ # Unit tests (services)
__mocks__/ # Static mocks for testing
npm install
npm test
const request = require('supertest');
const app = require('../../src/app');
describe('GET /api/users', () => {
it('should return 200 and a list of users', async () => {
const res = await request(app).get('/api/users');
expect(res.statusCode).toBe(200);
expect(Array.isArray(res.body)).toBe(true);
});
});
- Express
- Jest
- Supertest
MIT