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.
[{ a: 'cat' }, { a: 'dog' }].should.not.include({ a: 'cat' })
[{ a: 'cat' }, { a: 'dog' }].should.include.something.that.deep.equals({ a: 'cat' })
[{ a: 'cat' }, { a: 'dog' }].should.include.something.that.deep.equals({ a: 'cow' })
You are free to choose the syntactic variant you like most:
[4, 11, 15].should.include.one.below(10)
[4, 11, 15].should.contain.some.above(10)
[4, 11, 15].should.not.contain.any.above(20)
[{ a: 'cat' }, { a: 'dog' }].should.contain.a.thing.with.property('a', 'cat')
[{ a: 'cat' }, { a: 'dog' }].should.contain.an.item.with.property('a', 'dog')
All
Use the all
property on an array to test whether the assertion holds for all its elements.
[4, 11, 15].should.all.be.below(20)
[{ a: 'cat' }, { a: 'dog' }].should.all.have.property('a')
[4, 11, 15].should.all.be.above(20)
[{ a: 'cat' }, { a: 'dog' }].should.all.have.property('a', 'cat')
There are currently no syntactic variants for all
. Let me know if you need them.
Installation and usage
$ npm install chai-things
var chai = require("chai");
chai.should();
chai.use(require('chai-things'));