Skip to content

Deep equality with a set depth #64

@HoldYourWaffle

Description

@HoldYourWaffle

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions