在节点 mocha 中使用 expect 请求选项

request options with expect in node mocha

我想在我的单元测试中提供自定义 headers,目前我的单元测试是

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
});

我要加headers赞

var options = {
  url: 'community',
  headers: {
    'Authorization': 'Bearer ' + authToken 
  }
};

当我在 npmjs 中看到请求文档时。它要求我提供请求选项

request(options, callback);

如何在我的案例中提供自定义 headers,即如果我在我的单元测试中提供请求参数作为选项 object?

我相信 supertest 有一个 set() 来设置请求 headers:

request(sails.hooks.http.app)
  .post('/myurl')
  .set('Authorization', 'value')
  .send(userDetails)
  .expect('Content-Type', /json/)
  .expect(200)