javascriptnode.jsunit-testingtestingshould.js

Should.js: check if two arrays contain same strings


I have two arrays:

var a = ['a', 'as', 'sa'];
var b = ['sa', 'a', 'as'];

Is there anything special in shouldJS to test if these two arrays have same items? Anything Like

should(a).be.xyz(b)

that can test them? Here, xyz is what I am looking for.


Solution

  • A naive, but possibly sufficient solution would be to sort the arrays before comparing them:

    should(a.sort()).be.eql(b.sort())
    

    Note that sort() works in-place, mutating the original arrays.