jest-emotion: TypeError: node.getAttribute is not a function
See original GitHub issueCurrent behavior:
On some specific React components/trees, the jest-emotion serializer throws an error: TypeError: node.getAttribute is not a function
.
If I comment out the jest-emotion
serializer from setupTests.js
the snapshot is written properly.
To reproduce:
- Clone https://github.com/quid/refraction
cd refraction
yarn
git checkout 6b7a3f0746510779191d5547f357d9afca99227b
cd packages/expandable-table
yarn test
Expected behavior:
A snapshot should be written.
Environment information:
react
version: 16emotion
version: 10.0.15
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:9 (5 by maintainers)
Top Results From Across the Web
TypeError: getAttribute is not a function in JavaScript
The "getAttribute is not a function" error occurs for multiple reasons: calling the getAttribute method on a jQuery object instead of a DOM...
Read more >TypeError: abc.getAttribute is not a function - Stack Overflow
abc is a jQuery object, so it doesn't have a getAttribute() function. it has an attr() ... Calling a function on this that...
Read more >Elements.Getattribute Is Not A Function - ADocLib
getAttribute is not a function when trying to expand project details on the Projects page ... the jestemotion serializer throws an error: TypeError:...
Read more >Uncaught TypeError: a.getAttribute is not a function
Problem: Uncaught TypeError: a.getAttribute is not a function appears. Other observations: Aside from the error message, the delete button ...
Read more >HTML DOM Element getAttributeNode() Method - W3Schools
Definition and Usage · The Difference Between getAttribute() and getAttributeNode() · Alternative: · See Also: · Tutorial: · Reference: · Syntax · Parameters ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This comma is not insignificant. We can confirm this by inspecting the transformed output of this JSX:
As we may see here - the
comma
is present in thechildren
variadic argument of theReact.createElement
call. This means that you have passed an array of nodes to thetoHaveStyleRule
and that is a problem because it won’t be able (and shouldn’t be able) to handle this.So I don’t think this is a problem in our code - but what we could do is to introduce an explicit error message for a situation like this.
I managed to track this down to serializing fragments in deep mode: https://github.com/emotion-js/emotion/pull/1477/files#diff-1c3f3af1ec5f3c0a2955f0700c9520f6R115-R129