Skip to content

Pretty-printing jsdom objects is way too verbose #2146

@gaearon

Description

@gaearon

This is what I see with a single failing expectation:

gif

This is because jsdom has its implementation under a Symbol() key, and a single jsdom element brings the whole jsdom with it.

Can we fix it by adding some sort of pretty-printing for jsdom? I know that's what @yaycmyk attempted in jamiebuilds/pretty-format#47 but it received a comment:

I also don't think HTML printing should be a default. I don't actually want to pretty-print HTML elements in Jest like this.

If we really want to do this, the right way is to build a plugin and then use instanceof checks with the objects coming from jsdom.

Shall we do this them?

Another way to fix this specific issue would be to skip Symbol() keys since they're intentionally "private". The downside would be that comparing two objects with different values under Symbol keys would presumably miss those differences. We could maybe only print Symbol() keys if we know the difference is inside of them but skip them otherwise.

Yet another way to fix it would be to limit nesting when printing difference to something like 3. I think it's what Node does in console.log but I might be wrong.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions