austinbv austinbv - 1 month ago 9
Javascript Question

Equivalent to rspec =~ for arrays in Chai

Does Chai, matchers have an equilivent to rspecs

=~
(which means has all elements but order doesn't matter.

Passing example



[1, 2, 3].should =~ [2, 1, 3]


Failing



[1, 2, 3].should =~ [1, 2]

Answer

You can use members test that is available in the latest Chai version:

expect([4, 2]).to.have.members([2, 4]);
expect([5, 2]).to.not.have.members([5, 2, 1]);