Skip to content

Dump: Add Map and Set support to QUnit.dump.parse - #1840

Open
chiragbitoni wants to merge 1 commit into
qunitjs:mainfrom
chiragbitoni:fix/dump-map-set
Open

chiragbitoni wants to merge 1 commit into
qunitjs:mainfrom
chiragbitoni:fix/dump-map-set

Conversation

@chiragbitoni

Copy link
Copy Markdown

Fixes #1812.

Problem

QUnit.dump.parse(new Map([["a","b"],["c","d"]])) returns {} instead of showing Map contents. Same problem affects Set.

Root cause: QUnit.dump.typeOf() doesn't recognize Map or Set instances — they fall through to typeof obj which returns "object". The object parser then uses for...in to enumerate properties, which yields nothing for Map/Set (their entries are stored in private internal slots, not as own enumerable properties).

Fix

  1. Added Map and Set detection in typeOf() using the existing is() utility (which calls objectType() via Object.prototype.toString — the same approach used in assert.deepEqual).
  2. Added a map parser that formats as Map{key: value, ...}, respecting maxDepth and recursion tracking.
  3. Added a set parser that formats as Set{val1, val2, ...}, respecting maxDepth and recursion tracking.

Both parsers use .forEach() for iteration (not for...of) to avoid IE transpilation issues, matching the approach in src/core/equiv.js.

Tests

6 new tests added in test/main/dump.js covering empty/basic/shallow/recursion cases for both Map and Set. All tests guarded with QUnit.test.if(typeof Map === "function", ...) per the existing pattern for newer APIs.

Verification

  • npm run lint → 0 errors/warnings ✓
  • npm run build → clean rollup build ✓
  • node bin/qunit.js test/main/dump.js → 25/25 pass, 1 skip (DOM) ✓
  • node bin/qunit.js test/main/ → 271/271 pass, 42 skip, 4 todo ✓

Fixes qunitjs#1812.

Detect Map and Set instances in QUnit.dump.typeOf() and format their
entries in QUnit.dump.parse() rather than falling through to plain object
serialization (which yielded '{}' due to non-enumerable own properties).
Supports recursion tracking and maxDepth capping.

Signed-off-by: Chirag Bitoni <chiragbitoni4994@gmail.com>

This branch has not been deployed

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

QUnit.dump.parse returns an empty object for Maps

1 participant