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

mck picture mck · Jul 9, 2013 · Viewed 23.4k times · Source

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

Andreas Köberle picture Andreas Köberle · Jul 10, 2013

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})