使用chai-as-promise在已解析的promise对象上测试hasOwnProperty()

时间:2014-03-17 19:01:39

标签: javascript node.js testing mocha chai

我正在尝试运行以下测试:

describe('set()', function () {
    var returnedUser = session.set(user);

    it('should return a User object', function () {
        //this works fine
        return returnedUser.should.eventually.equal(user);
    });

    it('returned User object should have sessionId appended', function() {
        //DOES NOT WORK; always passes
        return returnedUser.should.eventually.hasOwnProperty('thisdoesnotexist');
    });
});

我正在尝试找出正确的语法来测试返回的User对象是否包含'sessionId'属性。有人知道怎么做吗?

1 个答案:

答案 0 :(得分:1)

通过仔细查看chaijs docs来了解这一点。

it('returned User object should have sessionId appended', function() {
    return returnedUser.should.eventually.include.keys('sessionId');
});