Ash*_*are 6 javascript mocha.js chai
我正在尝试使用chai js断言编写单元测试,并且想知道如何期望长度为零的数组作为值.
我的测试函数期望声明:
return expect(functionRetuningPromise()).to eventually.have.property("key1", []);
Run Code Online (Sandbox Code Playgroud)
运行mocha时的控制台输出:
AssertionError: expected { otherkey: otherVal, key1: [] } to have a property 'key1' of [], but got []
Run Code Online (Sandbox Code Playgroud)
我试过了deep.property,key1:"[]"没有成功
小智 16
我认为这有点简单
expect( value ).to.be.an( "array" ).that.is.empty
Run Code Online (Sandbox Code Playgroud)
关于什么
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;
})
Run Code Online (Sandbox Code Playgroud)
我忽略了属性断言的一部分变化.那么,它对我有用的是:
return expect(functionRetuningPromise()).to.eventually.have.property("key1").that.eql([]);
Run Code Online (Sandbox Code Playgroud)