摩卡柴-测试对象的多个属性

Var*_*eja 3 mocha.js chai

我想使用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);
        })
Run Code Online (Sandbox Code Playgroud)

但我得到以下错误: 在此处输入图片说明

Var*_*eja 5

找到了如何使用摩卡柴应该做到这一点,

函数名称是.should.have.keys() 只需将属性传递给此函数,它将检查它们是否应出现在要测试的对象中。

波纹管是代码

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