> Mocha Integration Testing

HTTP API and database integration testing with Mocha and chai-http.

fetch
$curl "https://skillshub.wtf/skillshub-team/catalog-batch5/mocha-integration?format=md"
SKILL.mdMocha Integration Testing

Mocha Integration Testing

HTTP API Tests

import chai from 'chai';
import chaiHttp from 'chai-http';
chai.use(chaiHttp);
const { expect } = chai;

describe('GET /api/users', () => {
    it('returns users', async () => {
        const res = await chai.request(app).get('/api/users');
        expect(res).to.have.status(200);
        expect(res.body).to.be.an('array');
    });

    it('creates user', async () => {
        const res = await chai.request(app).post('/api/users')
            .set('Authorization', 'Bearer token')
            .send({ name: 'Alice', email: 'a@b.com' });
        expect(res).to.have.status(201);
    });
});

Database Tests

before(async () => { await db.migrate(); });
afterEach(async () => { await db.query('DELETE FROM users'); });
after(async () => { await db.close(); });

┌ stats

installs/wk0
░░░░░░░░░░
first seenMar 18, 2026
└────────────

┌ tags

└────────────