Skip to content

stringify() drops contents of Set and Map #128

Description

@DmitrySharabin

Bug

stringify() returns the literal string "{}" for Set and Map values, regardless of their contents.

src/objects.js:270-272:

case "Set":
case "Map":
    return "{}";

Impact

Failing tests that compare these types produce uninformative output. With default deep equality, equals(new Set([1, 2, 3]), new Set([4, 5])) correctly returns false, but the failure message renders both sides as {}. The new formatDiff strategy picker (PR #127) falls back to the "stringified identically but not equal" hint — accurate but unhelpful.

Repro

import { equals } from "htest.dev/check";

export default {
    name: "Set diff",
    run: () => new Set([1, 2, 3]),
    expect: new Set([4, 5]),
    check: equals,
};

Output:

 Actual:   {} (Set)
 Expected: {} (Set)
 (values are stringified identically but not equal)

Fix sketch

Serialize Set and Map by walking their entries — similar to how Array is handled at src/objects.js:273-279.

Once fixed, the format-diff strategies (inline char-diff, multi-line -/+ block) handle these values correctly without further changes.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions