Chai Things
Chai Things adds support to Chai for assertions on array elements.
Examples
Something
Use the something
property on an array to test whether the assertion holds for one of its elements.
// Although they are equal, two different { a: 'cat' } objects are not the same a: 'cat' a: 'dog' shouldnot// Chai Things allows us to test deep equality on one of the elements a: 'cat' a: 'dog' shouldincludesomethingthatdeep// If the test fails, we get a descriptive message a: 'cat' a: 'dog' shouldincludesomethingthatdeep/* expected an element of [ { a: 'cat' }, { a: 'dog' } ] to deeply equal { a: 'cow' } */
You are free to choose the syntactic variant you like most:
4 11 15shouldincludeonebelow104 11 15shouldcontainsomeabove104 11 15shouldnotcontainanyabove20 a: 'cat' a: 'dog' shouldcontainathingwith a: 'cat' a: 'dog' shouldcontainanitemwith
All
Use the all
property on an array to test whether the assertion holds for all its elements.
// All items are below 204 11 15shouldallbebelow20// All items have a property 'a' a: 'cat' a: 'dog' shouldallhave// If the test fails, we get a descriptive message4 11 15shouldallbeabove20/* expected all elements of [ 4, 11, 15 ] to be above 20 */ a: 'cat' a: 'dog' shouldallhave/* expected all elements of [ { a: 'cat' }, { a: 'dog' } ] to have a property 'a' of 'cat', but got 'dog' */
There are currently no syntactic variants for all
. Let me know if you need them.
Installation and usage
$ npm install chai-things
var chai = ;chai;chai;