柴 js 期望 属性 值空数组
chai js expect property value empty array
我正在尝试使用 chai js 断言编写单元测试,并且想知道如何期望长度为零的数组作为值。
我的测试函数期望语句:
return expect(functionRetuningPromise()).to eventually.have.property("key1", []);
运行 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([]);
那
呢
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([]);
我觉得这个比较简单
expect( value ).to.be.an( "array" ).that.is.empty
我正在尝试使用 chai js 断言编写单元测试,并且想知道如何期望长度为零的数组作为值。
我的测试函数期望语句:
return expect(functionRetuningPromise()).to eventually.have.property("key1", []);
运行 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([]);
那
呢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([]);
我觉得这个比较简单
expect( value ).to.be.an( "array" ).that.is.empty