[Bug]: structuredClone is not defined

See original GitHub issue

Basic info:

  • Node.js version: 18.0.0
  • jsdom version: 19.0.0

Minimal reproduction case

Running a jest test that calls the structuredClone global using the jsdom environment

structuredClone();

I first opened this issue in the jest repo and was instructed to open it here.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:36
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
jacygaocommented, Jul 27, 2022

As an alternative, you could mock structuredClone in your test file:

global.structuredClone = jest.fn(val => {
    return JSON.parse(JSON.stringify(val));
});
2reactions
AideTechBotcommented, Aug 22, 2022

I can vouch that this is still an issue using jest-environment-jsdom v28.1.3

Read more comments on GitHub >

github_iconTop Results From Across the Web

`structuredClone` is not defined · Issue #12628 · facebook/jest
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue...
Read more >
"ReferenceError: structuredClone is not defined" using jest ...
I'm running tests with jest in a simple NodeJS app that uses typescript. My test is throwing an error: ReferenceError: structuredClone is not ......
Read more >
structuredClone() - Web APIs - MDN Web Docs
The global structuredClone() method creates a deep clone of a given value using the structured clone algorithm.
Read more >
structuredClone is not a function - LWC
However, when I attempt to use this in an LWC, I get the following error: [structuredClone is not a function].
Read more >
Deep-copying in JavaScript using structuredClone - web.dev
Non -primitive values are handled as references, meaning that the act of copying the value is really just copying a reference to the...
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