Mocha Integration

Mocha Integration Testing

ComeOnOliver Updated 61 repo stars

File contents

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(); });

ComeOnOliver/skillshub/tree/main/skills/skillshub-team/catalog-batch5/mocha-integration commit f7c88eaf8f

Frequently asked questions

npx skillmds@latest add comeonoliver/mocha-integration