gpt4 book ai didi

mocha.js - Mocha Chai - 测试对象的多个属性

转载 作者:行者123 更新时间:2023-12-02 22:59:58 27 4
gpt4 key购买 nike

我想使用 chai 应该断言检查我的响应对象是否包含提到的属性。

下面是我的代码片段:

chai.request(app)
.post('/api/signup')
.send(
data
)
.then(function (response) {
response.should.have.status(200);
response.body.should.have.property('active', 'mobileNumber', 'countryCode', 'username', 'email', 'id', 'createdAt', 'updatedAt', 'location');
done();
})
.catch(function (error) {
done(error);
})

但我收到以下错误: enter image description here

最佳答案

找到了如何使用 mocha chai-should 来实现它,

函数名称为.should.have.keys()只需将属性传递给此函数,它就会检查它们是否应该存在于您正在测试的对象中。

下面是代码

response.body.should.have.keys('active', 'mobileNumber', 'countryCode', 'username', 'email', 'id', 'organisationId', 'createdAt', 'updatedAt', 'location');

关于mocha.js - Mocha Chai - 测试对象的多个属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49280444/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com