25

Is it possible to assert that an array includes multiple specific items using chai?

For example, I would expect this to work:

['foo', 'bar'].should.include(['foo', 'bar']) 

Instead chai throws: "expected [ 'foo', 'bar' ] to include [ 'foo', 'bar' ]"

I also tried this but it only asserts that the first item is present:

['foo', 'bar'].should.include('foo', 'bar') // variable args instead of array 

What am I missing?

KyleMit
  • 30,350
  • 66
  • 462
  • 664
mockaroodev
  • 2,031
  • 1
  • 20
  • 24

1 Answers1

39

You can use members to expect array members.

Ex:

expect(['foo', 'bar']).to.include.members(['foo', 'bar'])
Douglas Liu
  • 1,592
  • 17
  • 11
  • 1
    Is the way to assert that: expect(['foo', 'bar'])"contains at least one of"(['foo', 'bar']) so the array contains one or more elements from other array Becouse .to.include.members is true if one array is exact the same as the other. I need to assert that array contains at least one value from other array – gagatek Oct 22 '20 at 10:25