【发布时间】:2021-01-21 19:47:10
【问题描述】:
我正在使用 chai 和 mocha 来测试我的 Node.js 之一。 我尝试使用的断言抛出错误。
未捕获的 AssertionError:预期 { Object (_events, _eventsCount, ...) } 具有属性“地址”
尝试使用断言验证以下响应对象和值:
Json 响应正文
{
"address": "value1",
"testware": "value2",
"status": false,
"linestatus": "online",
"optionalstatus": {
"line1": "offline",
"line2": "offline",
}
}
代码
describe('GET /getstatus Success Response (200)', () => {
it('Should return Status of line', (done) => {
chai.request(endpoint)
.get(getUrlWithQueryParamString({"url": "Passing get URL here", "method":"GET"}))
.end((err, res) => {
//console.log(res);
expect(res).to.have.status(200);
expect(res).to.have.property("body")
.and.have.property("address").equal("value1")
.and.have.property("testware").equal("value2")
.and.have.property("status").equal(false)
.and.have.property("linestatus").equal("online")
expect(res.body.optionalstatus.line1.to.include("offline"));
done();
});
});
【问题讨论】: