Node mocha array should contain an element

Explosion Pills picture Explosion Pills · Apr 1, 2015 · Viewed 13.4k times · Source

I want to do a simple assertion of something like

knownArray.should.include('known value')

The array is correct, but I simply can't figure out the proper assertion to use to check whether the array has this value (the index doesn't matter). I also tried should.contain but both of these throw an error that Object #<Assertion> has no method 'contain' (or 'include')

How can I check that an array contains an element using should?

Answer

Rodrigo Medeiros picture Rodrigo Medeiros · Apr 1, 2015

Should.js has the containEql method. In your case:

knownArray.should.containEql('known value');

The methods include, includes and contain you would find in chai.js.