vbardales / chai-properties

Properties matcher for chai that assert values have all the same attributes and values without asserting strict object equality.
16 stars 9 forks source link

Implement strict sub-object checking #2

Open vladlosev opened 10 years ago

vladlosev commented 10 years ago

Hi,

Thanks for this very nice chai plugin! IMHO, this functionality so useful, it should be integrated into the chai proper.

But here is the issue I've ran into this issue when using it. Currently, if the object under test has a property X that is itself an object, the assertion will only check that properties of expected.X are a subset of properties in actual.X. This may be dangerous as the users may be expecting the full comparison, and be missing hidden problems such as this one:

chai.expect({permissions: {limited: true, admin: true}})
  .to.have.properties({permissions: {limited: true}});

It would be nice to perform full equality rather than the subset check on the members of the expected properties, either by default or as a selectable option. Thanks!

qraynaud commented 9 years ago

For this I would rather recommend:

chai.expect({permissions: {limited: true, admin: true}})
  .to.have.property('permissions')
    .that.is.deep.equal({limited: true})
;
vladlosev commented 9 years ago

deep.equal only works if the set of the properties to compare is known beforehand.