在摩卡节点请求选项
我想在我的unit testing中提供自定义标题,目前我的unit testing是
request(sails.hooks.http.app) .post('/myurl') .send(userDetails) .expect('Content-Type', /json/) .expect(200) .end(function (err, res) { if(err) throw err; //do something });
我想添加标题
var options = { url: 'community', headers: { 'Authorization': 'Bearer ' + authToken } };
当我在npmjs中看到请求的文档。 它要求我提供选项来请求
request(options, callback);
我如何提供自定义标题在我的情况下,即如果我在unit testing中提供req参数作为选项对象?
我相信supertest
有一个set()
来设置请求标题:
request(sails.hooks.http.app) .post('/myurl') .set('Authorization', 'value') .send(userDetails) .expect('Content-Type', /json/) .expect(200)