user1Stats.should.be.instanceof(Object);
(user1Stats).should.have.keys();
I get the following error:
Error: keys required
at Object.Assertion.keys
The instanceof(Object)
works, but I want to make sure there is no data in it.
keys(object) method: The required object could be passed to the Object. keys(object) method which will return the keys in the object. The length property is used to the result to check the number of keys. If the length property returns 0 keys, it means that the object is empty.
keys method to check for an empty object. const empty = {}; Object. keys(empty). length === 0 && empty.
There are only seven values that are falsy in JavaScript, and empty objects are not one of them. An empty object is an object that has no properties of its own. You can use the Object.
user1Stats.should.be.an.Object();
user1Stats.should.be.empty();
or, using .and
to chain both asserts:
user1Stats.should.be.an.Object().and.be.empty();
P.S. By the way, your code also looks fine.
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