tj / should.js

BDD style assertions for node.js -- test framework agnostic
MIT License
2.75k stars 195 forks source link

Check if an Array includes an object equal to a specified object. #32

Closed RubenVerborgh closed 12 years ago

RubenVerborgh commented 12 years ago

Since include uses indexOf, it cannot test for equality.

I have added an includeEql method that tests whether an object equal to the specified one is present in the array.

One prominent case occurs when testing an array of arrays:

[[1],[2],[3]].should.not.include([3])
[[1],[2],[3]].should.not.include([2])
[[1],[2],[3]].should.not.include([4])

But, thanks to this extension:

[[1],[2],[3]].should.includeEql([3])
[[1],[2],[3]].should.includeEql([2])
[[1],[2],[3]].should.not.includeEql([4])