I am using the should.js library for assertions in my unit tests and was wondering how I would go about asserting that the contents of a Set
matches the expectation.
let actualValues = new Set();
actualValues.add(2);
actualValues.add(4);
actualValues.add(6);
actualValues.should.be....... ?
My first instinct was to use Array.from(actualValues)
and then compare that with the expected values; but naturally the ordering of actualValues
is undefined since it's a Set
.
The following works; but it seems quite verbose:
actualValues.size.should.be.eql(3);
actualValues.has(2).should.be.true();
actualValues.has(4).should.be.true();
actualValues.has(6).should.be.true();