nodejs / nodejs/node

Add `partialDeepEqual()` in strict assertion mode

Open
#62,327 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature request never-stale
Dominant language
JavaScript
Stars
122k
Forks
37.3k
Avg merge
4d 2h
Merged PRs (30d)
283

Description

What is the problem this feature will solve?

I use strict assertion mode in my tests:

import assert from "node:assert/strict";

assert.equal("...", "...");
assert.deepEqual({ "..." }, { "..." });
assert.partialDeepEqual({ "..." }, { "..." });

But the partialDeepEqual() doesn't exist. You have to use partialDeepStrictEqual() that has the word Strict in its name, whereas the other methods do not.

What is the feature you are proposing to solve the problem?

The "node:assert/strict" module should re-export partialDeepStrictEqual() with the name partialDeepEqual() so that function names are consistent in strict assertion mode.

Additional information

The partialDeepStrictEqual() function was added with https://github.com/nodejs/node/pull/54630. I couldn't find any references to the terms strict assertion mode.

"Re-export" takes place in two locations:

I don't think adding the following two lines is enough?

// if (options.strict) { 
this.partialDeepEqual = this.partialDeepStrictEqual; 

// assert.strict = ObjectAssign(strict, assert, { 
partialDeepEqual: assert.partialDeepStrictEqual, 

Because partialDeepEqual() doesn't exist in legacy assertion mode. So we need to manage the fact that the Assert type will be different between the two modes.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in lib/assert.js at the two linked export locations around lines 126-131 and 894-899, and inspect how strict and legacy assertion modes expose the Assert type. Add the strict-mode alias without adding it to legacy mode, then verify that both import forms expose partialDeepEqual while partialDeepStrictEqual remains available.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.