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

[Bug]: Jest fails to serialize custom elements with anonymous constructors #15137

Closed
KonnorRogers opened this issue Jun 19, 2024 · 1 comment · Fixed by #15138
Closed

[Bug]: Jest fails to serialize custom elements with anonymous constructors #15137

KonnorRogers opened this issue Jun 19, 2024 · 1 comment · Fixed by #15138

Comments

@KonnorRogers
Copy link
Contributor

Version

latest

Steps to reproduce

Reproduction here:

testing-library/dom-testing-library#1191 (comment)

class MyElement extends HTMLElement {}
window.customElements.define("my-element", class extends MyElement {})
window.customElements.get("my-element").name // => ""

export default () => <my-element></my-element>

test("Render app", () => {
  render(<App />)
  snapshot()
})

Expected behavior

Should properly serialize a custom element to HTML tags

Actual behavior

Renders the entire JS object

https://github.com/KonnorRogers/shoelace-nextjs-lazy/blob/main/app/__snapshots__/page.test.tsx.snap

Additional context

The test function in pretty-format expects the constructor to have a name

export const test: NewPlugin['test'] = (val: any) =>
val?.constructor?.name && testNode(val);

- export const test: NewPlugin['test'] = (val: any) =>
-  val?.constructor?.name && testNode(val);
+ export const test: NewPlugin['test'] = (val: any) =>
+  val?.constructor && testNode(val);

Environment

System:
    OS: macOS 14.4
    CPU: (8) arm64 Apple M1 Pro
  Binaries:
    Node: 20.9.0 - ~/.asdf/installs/nodejs/20.9.0/bin/node
    Yarn: 4.0.1 - ~/.asdf/installs/nodejs/20.9.0/bin/yarn
    npm: 10.1.0 - ~/.asdf/plugins/nodejs/shims/npm
    pnpm: 9.1.1 - ~/.asdf/installs/nodejs/20.9.0/bin/pnpm
  npmPackages:
    jest: ^29.7.0 => 29.7.0
Copy link

github-actions bot commented Aug 2, 2024

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 Aug 2, 2024
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.

1 participant