Skip to content

Update assert.deepStrictEqual docs to mention .constructor property #60239

@chharvey

Description

@chharvey

Affected URL(s)

https://nodejs.org/docs/latest-v24.x/api/assert.html#comparison-details_1

Description of the problem

I’ve been running into an bug in my code where assert.deepStrictEqual(a, b) was throwing unexpectedly.

To make a long story short, a and b were instances of a derived class that returned a new Proxy object in its constructor. The handler for this proxy set a new Function.prototype.bind call on any function object from the target, but this accidentally caught the target.constructor property in the line of fire — the intent was to only rebind instance methods. Basically, a and b shared the same prototype, but had unequal .constructor properties due to the incorrect binding.

The docs for assert.deepStrictEqual say that only the [[Prototype]] and enumerable own properties are checked, so I was scratching my head trying to track down the bug, meticulously checking my code against the docs point by point. Only by stepping through the Node.JS source code did I see where .constructor is accessed. Then I found the new docs for util.isDeepStrictEqual, which in v24 has been updated to mention explicitly that constructors are checked. This would’ve been good to know!

So this issue is a request to update the assert.deepStrictEqual docs by adding a bullet point stating how object constructors are included in the comparison algorithm. Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    assertIssues and PRs related to the assert subsystem.docIssues and PRs related to the documentations.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions