Chai Immutable
This provide a set of Chai assertions for Facebook's Immutable library for JavaScript collections.
Installation
Install via npm:
npm install chai-immutable
You can then use this plugin as any other Chai plugins:
var chai = require('chai');
var chaiImmutable = require('chai-immutable');
chai.use(chaiImmutable);
API Reference
.empty
Asserts that the immutable collection is empty.
expect(List()).to.be.empty;
expect(List.of(1, 2, 3)).to.not.be.empty;
.equal(collection)
- @param { Collection } collection
Asserts that the values of the target are equvalent to the values of
collection
. Aliases of Chai's original equal
method are also supported.
var a = List.of(1, 2, 3);
var b = List.of(1, 2, 3);
expect(a).to.equal(b);
.size(value)
Asserts that the immutable collection's size
property has the expected
value.
expect(List.of(1, 2, 3)).to.have.size(3);
It can also be used as a chain precursor to a value comparison for the
size
property.
expect(List.of(1, 2, 3)).to.have.size.least(3);
expect(List.of(1, 2, 3)).to.have.size.most(3);
expect(List.of(1, 2, 3)).to.have.size.above(2);
expect(List.of(1, 2, 3)).to.have.size.below(4);
expect(List.of(1, 2, 3)).to.have.size.within(2,4);
Similarly to length
/lengthOf
, sizeOf
can be used as an alias of
size
:
expect(List.of(1, 2, 3)).to.have.sizeOf(3);