Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is this lib still necessary? #73

Open
stevenvachon opened this issue Jul 28, 2019 · 2 comments
Open

Is this lib still necessary? #73

stevenvachon opened this issue Jul 28, 2019 · 2 comments

Comments

@stevenvachon
Copy link

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

@aloisklink
Copy link

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

@kkm000
Copy link

kkm000 commented Sep 7, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants