I am testing an express API with supertest.
I couldn\'t get multiple requests in a test case to work with supertest. Below is what i tried in a test case. But the test c
I built upon Tim’s reply but used async.waterfall
instead, to be able to do assert tests on the results (note: I use Tape here instead of Mocha):
test('Test the entire API', function (assert) {
const app = require('../app/app');
async.waterfall([
(cb) => request(app).get('/api/accounts').expect(200, cb),
(results, cb) => { assert.ok(results.body.length, 'Returned accounts list'); cb(null, results); },
(results, cb) => { assert.ok(results.body[0].reference, 'account #0 has reference'); cb(null, results); },
(results, cb) => request(app).get('/api/plans').expect(200, cb),
(results, cb) => request(app).get('/api/services').expect(200, cb),
(results, cb) => request(app).get('/api/users').expect(200, cb),
],
(err, results) => {
app.closeDatabase();
assert.end();
}
);
});