mck mck - 1 month ago 9
Javascript Question

Mocha, Chai: Assert that Object is included in an Array of Objects

Chai has a nice way to assert if an Array includes a certain element

expect([1,2,3]).to.include(2);


What I would like is something similar, given an Array of Objects:

expect([{a:1},{b:2}]).to.include({b:2});


Is this possible?

Answer

Take a look at the Chai Things plugin, that does what you want:

[{a:1},{b:2}].should.include.something.that.deep.equals({b:2})