Skip to content

assert: partialDeepStrictEqual rejects Sets that deepStrictEqual accepts #67317

Closed

Description

@trackoor

Version

v26.13.0, also v28.0.0-nightly20261107a43bfb5bb2

Platform

Linux 6.1.0-54-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.190-1 (2026-10-16) x86_64 GNU/Linux

Subsystem

assert, util

What steps will reproduce the bug?

const assert = require('node:assert');
const util = require('node:util');

const actual = new Set([[1, 2], [1]]);
const expected = new Set([[1], [1, 2]]);

console.log(util.isDeepStrictEqual(actual, expected));
console.log(util.isPartialDeepStrictEqual(actual, expected));

assert.deepStrictEqual(actual, expected);
assert.partialDeepStrictEqual(actual, expected);
console.log('ok');

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

Always. An element of actual must partially match an element of expected that is not its exact counterpart. The same happens with Sets of objects and with object-keyed Maps:

util.isPartialDeepStrictEqual(new Set([{ a: 1, b: 1 }, { a: 1 }]), new Set([{ a: 1 }, { a: 1, b: 1 }])); // false
util.isPartialDeepStrictEqual(new Map([[{ a: 1, b: 1 }, 1], [{ a: 1 }, 1]]), new Map([[{ a: 1 }, 1], [{ a: 1, b: 1 }, 1]])); // false
util.isPartialDeepStrictEqual(new Set([[1, 2], [1], [3]]), new Set([[1], [1, 2], [3]])); // false

What is the expected behavior? Why is that the expected behavior?

true
true
ok

The docs say partialDeepStrictEqual "always passes the same test cases as assert.deepStrictEqual()" and that Set items are compared unordered.

What do you see instead?

true
false
node:internal/assert/utils:146
  throw error;
  ^

AssertionError [ERR_ASSERTION]: Values have same structure but are not reference-equal:

Set(2) {
  [
    1
  ],
  [
    1,
    2
  ]
}

Additional information

compareSmallSets, partialObjectSetEquiv and partialObjectMapEquiv in lib/internal/util/comparisons.js pair each element with the first unclaimed partial match, so [1, 2] takes [1] and [1] is left with nothing to match. Matching exact pairs first (or backtracking) would fix it.

Found with a differential-testing tool; the report was drafted with AI assistance and reviewed and edited by me.

Credit: https://ucsbplse.github.io/

Activity

  1. Stella050408 commented on Nov 8, 2026

    @Stella050408

    I'd like to work on this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions