我有一个断言失败:
断言:expect(obj1).to.deep.eq(expected);
失败是因为obj1有一个updatedAt时间戳:
"updatedAt": 1510356196161
我希望能够在expected
上说:
{
updatedAt: chai.any(number),
}

相当于jasmine.any。 chai中是否存在这个或类似的概念?
答案 0 :(得分:1)
不幸的是,看起来该功能尚未实现: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');
答案 1 :(得分:0)
您是否尝试过以下操作?
expect(obj1.updatedAt).to.be.a('number');