arraysnode.jsmocha.jsshould.js

Node mocha array should contain an element


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?


Solution

  • 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.