Hi,
I would like to prebuild using a function my request to prevent code duplication, here a basic example
const request = require('supertest');
const initRequest = () => request(app).set('X-Custom-Header', 'test')
initRequest().get('/blog')
initRequest().get('/contact')
To prevent doing
const request = require('supertest');
request(app).get('/blog').set('X-Custom-Header', 'test').get('/blog')
request(app).get('/blog').set('X-Custom-Header', 'test').get('/contact')
@ajouve Yes, you could try using a superagent plugin for that.
TDLR:
function custom(request) {
request.set('X-CUSTOM-HEADER', 'test');
// other shared configuration
}
request(app).get('/blog').use(custom);
I close it.
Thanks @jonathansamines and @pcraig3 for your contribution. 馃檹
Most helpful comment
@ajouve Yes, you could try using a superagent plugin for that.
TDLR: