Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
stefanbuck opened this issue Jan 4, 2018 · 6 comments · Fixed by #5246
Closed

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

stefanbuck opened this issue Jan 4, 2018 · 6 comments · Fixed by #5246

Comments

@stefanbuck
Copy link

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]

@rogeliog
Copy link
Contributor

rogeliog commented Jan 5, 2018

I can reproduced the same error, not sure what it is

@thymikee
Copy link
Collaborator

thymikee commented Jan 5, 2018

cc @pedrottimark

@zouxuoz
Copy link
Contributor

zouxuoz commented Jan 8, 2018

@rogeliog

jan-08-2018 12-17-31

I think it's not a bug, because DOMStringMap is very large object and Node can be fall in this case.

We can hardcode custom serialization for this case, but I'm think it's bad way.

It's a JSDOM problem, because browser doesn't have it. May be this jsdom/jsdom#1129 update resolve it.

@SimenB
Copy link
Member

SimenB commented Jan 8, 2018

We can hardcode custom serialization for this case, but I'm think it's bad way.

We do that for lots of stuff already, including HTMLElements

@zouxuoz
Copy link
Contributor

zouxuoz commented Jan 8, 2018

@SimenB oh, thx, I find it and can fix this bug.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants