ember-cli-custom-assertions-collection icon indicating copy to clipboard operation
ember-cli-custom-assertions-collection copied to clipboard

arrayContainsAll

Open SlyDen opened this issue 9 years ago • 5 comments

For use case, like

arr2.forEach(item => {
  assert.arrayContains(arr1, item, "arr1 contains all items from arr2");
});

it is nice to implement simplified form:

arrayContainsAll(arr1, arr2)

SlyDen avatar Oct 09 '15 08:10 SlyDen

What comparison function would you implement for that?

lolmaus avatar Oct 09 '15 08:10 lolmaus

I would also add an option to provide custom compare function ... e.g. I have complex objects in an array and want to compare them by certain field(s) and others I don't care

SlyDen avatar Oct 09 '15 08:10 SlyDen

Custom compare function is an awesome idea. Might be introduced to quite a few assertions.

On the other hand, if you're using a custom function, why not just do an ad-hoc assertion with assert.ok?

lolmaus avatar Oct 09 '15 08:10 lolmaus

I think a custom compare function makes sense when the assertion is complex (e. g. using a loop under the hood).

E. g. it's useless to introduce a custom compare function to arrayContains, but will still be useful for arrayContainsAll.

What do you think?

lolmaus avatar Oct 09 '15 08:10 lolmaus

Solution will bubble up during implementation and some real use case ... will start from simple

SlyDen avatar Oct 09 '15 09:10 SlyDen