Skip to content

Snapshot serializer doesn't work with DOMStringMap and NamedNodeMap #5233

@stefanbuck

Description

@stefanbuck

Do you want to request a feature or report a bug?
I suppose this could be considered a feature request.

What is the current behavior?

Jest throws an error when I try to serialize a DOMStringMap or NamedNodeMap. The output is:

RangeError: Invalid string length

If the current behavior is a bug, please provide the steps to reproduce and
either a repl.it demo through https://repl.it/languages/jest or a minimal
repository on GitHub that we can yarn install and yarn test.

The test is very simple:

const el = document.createElement('div');
el.dataset.foo = 'bar';

expect(el.dataset).toMatchSnapshot();

Same behavior for NamedNodeMap

const el = document.createElement('div');
el.dataset.foo = 'bar';

expect(el.attributes).toMatchSnapshot();

What is the expected behavior?

Jest should be able to serialize DOMStringMap and NamedNodeMap so I can reduce snapshot output to the values which I am interested in.

As a workaround, I spread the values into a new object.

expect({...el.dataset}).toMatchSnapshot();

Please provide your exact Jest configuration and mention your Jest, node,
yarn/npm version and operating system.

[email protected]
[email protected]
[email protected]

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