debitoor / chai-subset

"containSubset" object properties matcher for Chai
http://chaijs.com/plugins/chai-subset/
MIT License
82 stars 20 forks source link

Expect subset to contain one of #39

Closed deecewan closed 8 years ago

deecewan commented 8 years ago

If I am returned an array of 1 object, and there are two possible objects it could be, it'd be great to be able to check if one of the objects contains the subset.

For example, list can be one of

[{ 
  name: "test1",
  value: "abc",
},{
  name: "test2",
  value: "def"
}]
expect(list).to.have.lengthOf(1); // passes
expect(list).to.containSubset.oneOf([{name: "test1"}, {name: "test2"}]); // passes

If this is already there, that's awesome, but I can't find it.

eagleeye commented 8 years ago

Hi @deecewan, "one of" is opposite to "containSubset", so you can write your test in different way:

var list = [{ 
  name: "test1",
  value: "abc",
},{
  name: "test2",
  value: "def"
}];
expect(list).to.containSubset([{name: "test1"}]);

If this is not that you need - then i would suggest you to write another plugin for chai and call it "oneOf". The purpose of 'chai-subset' is different.

deecewan commented 8 years ago

yeah, i have found the Chai version. I was more wanting subset, because it allows for a subset of properties.

Thanks for getting back to me, tho.