Skip to content

deepStrictEqual not commutative by not accounting for non-enumerable properties #37710

Closed
@nmalyschkin

Description

@nmalyschkin
  • Version:
    • 14.x (but probably also others)
  • Platform:
    • all

What steps will reproduce the bug?

const { deepStrictEqual } = require("assert");

const a = {};
const b = {};

a.x = 1;

Object.defineProperties(b, {
  x: {
    value: 1,
    writable: true,
  },
  y: {
    value: 5,
    writable: true,
    enumerable: true,
    configurable: true,
  },
});

console.log({ a, b });
deepStrictEqual(a, b); // does not assert
deepStrictEqual(b, a); // does assert

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior?

I expect deepStrictEqual to be at least commutative. (Whether it should handle non-enumerable properties may be up for discussion)

What do you see instead?

deepStrictEqual(b, a) does throw an assertion while deepStrictEqual(a, b) does not.

Additional information

If you point me in the right direction I'm willing to fix it myself.

Metadata

Metadata

Assignees

Labels

assertIssues and PRs related to the assert subsystem.confirmed-bugIssues with confirmed bugs.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions