我有一个API,它的响应头为Keep-Alive,其值如下
Keep-Alive →timeout=15, max=100
我想断言值超时至少为10,最多为100。早些时候,我使用的是邮递员BDD库,并有以下代码
let keepAlive = response.getHeader("Keep-Alive");
// Make sure it contains "max=##"
let match = /max=(\d+)/.exec(keepAlive);
expect(match).to.be.an("array").and.not.empty;
// Make sure the max is between 98 and 100
let max = parseInt(match[1]);
expect(max).to.be.at.least(15).and.at.most(100); 但是,如果我使用Chakram,则getHeader函数与TypeError: response.getHeader is not a function一起出错。有没有人知道如何使用Chakram获取标头值。
发布于 2018-04-09 01:22:55
这是在Chakram中获取头值的方法。以验证响应是否采用json格式。expect(response).to.have.header('content-type', 'application/json; charset=utf-8'));
Chakram返回的响应是一个承诺,应该这样处理。因此,获取“保持生存”头值:
return chakram.get(serverUrl, params)
.then( chakramResponse => {
let keepAlive = chakramResponse.response.headers['Keep-Alive'];
let match = /max=(\d+)/.exec(keepAlive);
return expect(match).to.be.an("array").and.not.empty;
let max = parseInt(match[1]);
return expect(max).to.be.at.least(15).and.at.most(100);
});https://stackoverflow.com/questions/49651780
复制相似问题