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?
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?
You can use deep method for the array of objects.
You can find more examples using deep method here: http://chaijs.com/api/bdd/#method_deep
The main point to remember here is about reference types.
Here is an alternative and non order dependent approach for collections:
array
You can also use this with a
deep
flag for comparison of objects:array of objects
object
Take a look at the Chai Things plugin, that does what you want: