nodejs / nodejs/node

Add `partialDeepEqual()` in strict assertion mode

Offen
#62,327 5 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

feature request never-stale
Vorherrschende Sprache
JavaScript
Sterne
122k
Forks
37.3k
Ø Merge
4 T. 2 Std.
Gemergte PRs (30 T.)
283

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne in lib/assert.js an den beiden verknüpften Export-Stellen um die Zeilen 126–131 und 894–899 und untersuche, wie die strict- und legacy-Assertionsmodi den Assert-Typ verfügbar machen. Füge den Alias nur im strict-Modus hinzu, ohne ihn dem legacy-Modus hinzuzufügen, und überprüfe anschließend, dass beide Importformen partialDeepEqual verfügbar machen, während partialDeepStrictEqual weiterhin verfügbar bleibt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript
Bereich
api
Issue-Typ
Feature
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Ruhig
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
68/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.