柴相当于 jasmine.any?

chai equivalent of jasmine.any?

我有一个断言失败:

断言:expect(obj1).to.deep.eq(expected);

它失败了,因为 obj1 有一个 updatedAt 时间戳:

"updatedAt": 1510356196161

我想在 expected 上说:

{
    updatedAt: chai.any(number),
}

相当于jasmine.any。 chai 中是否存在这个或类似的概念?

您尝试过以下方法吗?

expect(obj1.updatedAt).to.be.a('number');

很遗憾,该功能似乎尚未实现:https://github.com/chaijs/chai/issues/644#issuecomment-336197639

到目前为止,我发现进行此类断言的最佳方法是逐项提出:

expect(obj1).to.have.property('updatedAt').that.is.a('number');
expect(obj1).to.have.property('deletedAt').that.is.a('null');
expect(obj1).to.have.property('name').that.equals('John Doe');