You can do this using the supertest library (using it in the application, not in the test):
var handleRequest = require('supertest');
var request = handleRequest(app)[params.method](params.path)
.set('Accept', 'application/json')
.set(params.headers);
if (body) request.send(params.body);
request.end(function (err, resp) {
console.log(resp.body);
});
where paramsis the object with the request parameters that you want to process, params.methodshould be a lowercase HTTP verb.
Alternatively, you can use mocks for request and response objects and call:
app.handle(reqMock, resMock, cb)
source
share