debitoor / chai-subset

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

Shallow subsets #58

Closed oleg-codaio closed 7 years ago

oleg-codaio commented 7 years ago

Any thoughts on adding a containSubsetShallow or something? (FWIW, I would expect containSubset to be shallow by default, and containSubsetDeep to perform recursive subsetting, but that would be a breaking change).

I'm using chai-subset to assert props on React components, so that rather than doing something like this:

assert.equal(myComponent.props.prop1, "somevalue");
assert.equal(myComponent.props.prop2, 123);
assert.equal(myComponent.props.prop3, {a: 123});

I can just do:

assert.containSubset(myComponent.props, {
  prop1: "somevalue",
  prop2: 123,
  prop3: {a: 123},
});

However, there is no need to perform recursive subset checking in this case; I would just want to use deepEqual instead on each of the matched props to ensure that their value is as expected. Has anyone proposed something like this, or would it make sense do have this option as part of this library?

ebdrup commented 7 years ago

Single purpose modules are great, this sounds like a different module with a different purpose.