我正在使用chakram来测试API,每当我在之前()中使用.then时,我总是在测试"it“时得到一个错误。我不确定我做错了什么,但我认为这与我的回报有关。
describe('create group', function() {
before('test', function() {
return banana = chakram.request("POST", `${url}`, {headers, body}
}).then(function (json) {
test = json.body
})
})
it("should return a 200 status when creating groups", function () {
console.log(test)
return expect(banana).to.have.status(201)
})
})返回的错误为TypeError: Cannot read property 'response' of undefined
发布于 2019-06-16 03:12:33
在答案出现之前,你把非答案抛给了香蕉。
这就是为什么香蕉是空的。
describe('create group', () => {
let bananaResponse;
before('test', () => {
return chakram.request("POST", `${url}`, {headers, body}
).then((responseJson) => {
bananaResponse = responseJson;
})
})
it("should return a 200 status when creating groups", () => {
console.log(bananaResponse.body);
return expect(bananaResponse).to.have.status(201);
})
})你可以试试。
https://stackoverflow.com/questions/50474825
复制相似问题