question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

jest-emotion: TypeError: node.getAttribute is not a function

See original GitHub issue

Current 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:

  1. Clone https://github.com/quid/refraction
  2. cd refraction
  3. yarn
  4. git checkout 6b7a3f0746510779191d5547f357d9afca99227b
  5. cd packages/expandable-table
  6. yarn test

Expected behavior:

A snapshot should be written.

Environment information:

  • react version: 16
  • emotion version: 10.0.15

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Andaristcommented, May 15, 2022

This comma is not insignificant. We can confirm this by inspecting the transformed output of this JSX:

// input
const component = renderer.create(
  <ThemeProvider theme={theme}>
    <Div color-mobile="blue">Honorable</Div>,
  </ThemeProvider>
);

// output
const component = renderer.create(
  React.createElement(
    ThemeProvider,
    { theme: theme },
    React.createElement(Div, { "color-mobile": "blue" }, "Honorable"),
    ","
  )
);

As we may see here - the comma is present in the children variadic argument of the React.createElement call. This means that you have passed an array of nodes to the toHaveStyleRule 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.

1reaction
liamcmitchell-sccommented, Aug 20, 2019

I managed to track this down to serializing fragments in deep mode: https://github.com/emotion-js/emotion/pull/1477/files#diff-1c3f3af1ec5f3c0a2955f0700c9520f6R115-R129

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found