[英]chai js expect property value empty array
我正在尝试使用 chai js 断言编写单元测试,并且想知道如何期望 arrays 具有零长度作为值。
我的测试 function 期望声明:
return expect(functionRetuningPromise()).to eventually.have.property("key1", []);
控制台 Output 运行 mocha:
AssertionError: expected { otherkey: otherVal, key1: [] } to have a property 'key1' of [], but got []
我试过deep.property
, key1:"[]"
没有成功
我忽略了属性断言的一部分变化。 那么,它对我有用的是:
return expect(functionRetuningPromise()).to.eventually.have.property("key1").that.eql([]);
我认为这有点简单
expect( value ).to.be.an( "array" ).that.is.empty
关于什么
return
expect(functionRetuningPromise()).to.eventually.have.property("key1").that.satisfy(function (value) {
expect(value).to.be.instanceof(Array);
expect(value).to.have.length.above(0);
return true;
})
这应该可以解决问题
expect(value).to.deep.equal([]);
这是chai.js的可能解决方案,应该:
const should = chai.should();
res.should.have.lengthOf(0)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.