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

Exclude specific nested key and not every? #41

Closed
TomerFi opened this issue Dec 30, 2022 · 4 comments
Closed

Exclude specific nested key and not every? #41

TomerFi opened this issue Dec 30, 2022 · 4 comments

Comments

@TomerFi
Copy link

TomerFi commented Dec 30, 2022

Hello

Cool project, thank you very much for sharing!
Is there a way for excluding a specific nested key? not every key.

Instead of this:

expect({a: 'aa', b: { a: 'hey', c: 'dd' }, c: 'dd1'})
    .excludingEvery('c')
    .to.deep.equal(({a: 'aa', b: { a: 'hey'}}));

Something like this:

expect({a: 'aa', b: { a: 'hey', c: 'dd' }, c: 'dd1'})
    .excluding('b.c')
    .to.deep.equal(({a: 'aa', b: { a: 'hey'}, c: 'dd1'}));
@mesaugat
Copy link
Owner

@TomerFi There's no such support at the moment. However, you can just expect/assert b separately by taking it out of the main object.

const { b } = {a: 'aa', b: { a: 'hey', c: 'dd' }, c: 'dd1'};
expect(b).excluding(c).to.deep.equal(b);

Hope it solves your issue.

Relates to #40

@TomerFi
Copy link
Author

TomerFi commented Jan 4, 2023

Yes, thanks.
For the record, this should be coupled with another statement because I need to assert for the outer keys as well, so this should be something like:

const res = {a: 'aa', b: { a: 'hey', c: 'dd' }, c: 'dd1'};
expect(res).excluding('b').to.deep.equal({a: 'aa', c: 'dd1'});
expect(res.b).excluding('c').to.deep.equal({ a: 'hey' });

Thanks @mesaugat this is a really useful plugin, I'll watch #40.
Unless you want to keep it open for tracking, feel free to close this issue.

@mesaugat
Copy link
Owner

mesaugat commented Jan 4, 2023

@TomerFi Yes, you are correct. I left out the outer keys in hopes that you would understand.

@mesaugat mesaugat pinned this issue Aug 14, 2023
@mesaugat
Copy link
Owner

Closing the issue.

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

2 participants