Skip to content
New issue

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

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

Already on GitHub? # to your account

Deep equality with a set depth #64

Open
HoldYourWaffle opened this issue Apr 2, 2020 · 0 comments
Open

Deep equality with a set depth #64

HoldYourWaffle opened this issue Apr 2, 2020 · 0 comments

Comments

@HoldYourWaffle
Copy link

Is it possible to limit the deep equality comparison to a certain depth?

For example:

const a = {
    foo: {
        bar: {
            baz: "qux"
        }
    }
}

const b = {
    foo: { // compared deeply
        bar: { // compared by identity (===)
            baz: "qux"
        }
    }
}

// this passes, since 'a' and 'b' are structurally equal
expect(a).to.deep.equal(b);

// this would fail, since the 'bar' object would be compared by identity
expect(a).to.deep.depth(1).equal(b);

In my real-world scenario the bar object would of course be a lot more complicated. Comparing these by identity is more than sufficient, and deep-equality even runs into issues due to circular references.

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

No branches or pull requests

1 participant