为chai请求添加自定义的http头
我正在使用node.js构build应用程序,并使用mocha + chai进行testing。 有没有一种方法可以将自定义标题添加到我的GET和POST chai请求?
例如,我想要的东西像(半伪代码):
chai.request(server) .get('/api/car/' + data.car_id) .headers({'some_custom_attribute':'some_value'}) .end(function(err, res) { //do something });
同样的post:
chai.request(server) .post('/api/car/') .headers({'some_custom_attribute':'some_value'}) .send({car_id: 'some_car_id'}) .end(function(err, res) { //do something });
有人可以帮忙吗?
提前致谢!
使用set
函数来设置http头:
chai.request(server) .get('/api/car/' + data.car_id) .set('some_custom_attribute', 'some_value') .end(function(err, res) { //do something });
的build立,请求