I'm trying to write a unit test using chai js assertion, and was wondering how to expect arrays with zero length as values.
My Test function expect statement:
return expect(functionRetuningPromise()).to eventually.have.property("key1", []);
Console Output on running mocha:
AssertionError: expected { otherkey: otherVal, key1: [] } to have a property 'key1' of [], but got []
I have tried deep.property
, key1:"[]"
with no success
Note expect and should uses chainable language to construct assertions, but they differ in the way an assertion is initially constructed. In the case of should , there are also some caveats and additional tools to overcome the caveats. var expect = require('chai').
Chai is a BDD / TDD assertion library for node and the browser that can be delightfully paired with any javascript testing framework.
Chai is such an assertion library, which provides certain interfaces to implement assertions for any JavaScript-based framework. Chai's interfaces are broadly classified into two: TDD styles and BDD styles.
This should do the trick
expect(value).to.deep.equal([]);
I think this is a little plainer
expect( value ).to.be.an( "array" ).that.is.empty
What about
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;
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With