Repository navigation
Dump: Add Map and Set support to QUnit.dump.parse - #1840
Open
chiragbitoni wants to merge 1 commit into
Open
chiragbitoni wants to merge 1 commit into
chiragbitoni wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 recognizeMaporSetinstances — they fall through totypeof objwhich returns"object". Theobjectparser then usesfor...into enumerate properties, which yields nothing for Map/Set (their entries are stored in private internal slots, not as own enumerable properties).Fix
MapandSetdetection intypeOf()using the existingis()utility (which callsobjectType()viaObject.prototype.toString— the same approach used inassert.deepEqual).mapparser that formats asMap{key: value, ...}, respectingmaxDepthand recursion tracking.setparser that formats asSet{val1, val2, ...}, respectingmaxDepthand recursion tracking.Both parsers use
.forEach()for iteration (notfor...of) to avoid IE transpilation issues, matching the approach insrc/core/equiv.js.Tests
6 new tests added in
test/main/dump.jscovering empty/basic/shallow/recursion cases for both Map and Set. All tests guarded withQUnit.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 ✓