chai-subset icon indicating copy to clipboard operation
chai-subset copied to clipboard

Is this lib still necessary?

Open stevenvachon opened this issue 6 years ago • 2 comments

... now that chai has deep.contain()

stevenvachon avatar Jul 28 '19 11:07 stevenvachon

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);

aloisklink avatar Sep 11 '19 15:09 aloisklink

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; } } });

kkm000 avatar Sep 07 '20 06:09 kkm000