Mocha Chai - 测试对象的多个属性
Mocha Chai - Test multiple properties of object
我想使用 chai should 断言检查我的响应对象是否包含提到的属性。
下面是我的代码片段:
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);
})
但我遇到以下错误:
找到了如何使用 mocha 实现它 chai-should,
函数名称是.should.have.keys()
只需将属性传递给此函数,它将检查它们是否应该存在于您正在测试的对象中。
下面是代码
response.body.should.have.keys('active', 'mobileNumber', 'countryCode', 'username', 'email', 'id', 'organisationId', 'createdAt', 'updatedAt', 'location');
如果您专门使用 Chai(例如在 Postman 中),则以下函数串将成功地帮助您:
response.body.to.include.all.keys("active", "mobileNumber");
The full list of API's (including an example of the above) can be found here.
我想使用 chai should 断言检查我的响应对象是否包含提到的属性。
下面是我的代码片段:
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);
})
但我遇到以下错误:
找到了如何使用 mocha 实现它 chai-should,
函数名称是.should.have.keys()
只需将属性传递给此函数,它将检查它们是否应该存在于您正在测试的对象中。
下面是代码
response.body.should.have.keys('active', 'mobileNumber', 'countryCode', 'username', 'email', 'id', 'organisationId', 'createdAt', 'updatedAt', 'location');
如果您专门使用 Chai(例如在 Postman 中),则以下函数串将成功地帮助您:
response.body.to.include.all.keys("active", "mobileNumber");
The full list of API's (including an example of the above) can be found here.