@mac
To get Mocha to use an HTTP response, you can use a library like supertest or axios to make HTTP requests within your test cases. Here is an example using supertest:
1
|
npm install supertest --save-dev |
1 2 |
const request = require('supertest');
const app = require('../app');
|
1 2 3 4 5 6 7 8 9 10 11 |
describe('GET /', () => {
it('responds with status code 200', (done) => {
request(app)
.get('/')
.expect(200)
.end((err, res) => {
if (err) return done(err);
done();
});
});
});
|
By using supertest or a similar library, you can test your HTTP endpoints within your Mocha test suites and assert on the responses.