chai-subset
chai-subset copied to clipboard
Is this lib still necessary?
... now that chai has deep.contain()
I believe it is, since deepInclude only works from the first level (see https://www.chaijs.com/api/assert/#method_deepinclude):
const subset = {
a: 'b',
e: {
// missing "foo": "bar"
baz: {qux: 'quux'},
}
};
const obj = {
a: 'b',
c: 'd',
e: {
foo: "bar",
baz: {qux: "quux"},
}
};
// PASSES
expect(obj).to.containSubset(subset);
// FAILS, as obj.e does not contain "foo": "bar".
expect(obj).deep.contain(subset);
Another feature not offered by chai, AFAIK, is the ability to provide an asserting function at any level.
Test that an object contains the key axes, which in turn contains distro, which in turn has something under an empty string key, do not care about the value:
assert.containSubset(control.BBCI, {
axes: { distro: { '': () => true } }
});
Or even a more complex scenario with a nested assertion:
assert.containSubset(control.BBCI.stages, {
gcb_stage: {
gcb: (x: unknown[]) => {
assert.strictEqual(2, x.length);
return true; } } });