add structuredClone to jest JSDOMEnvironment (#36213)

This commit is contained in:
Sakshyam Shah
2024-01-03 20:56:29 +00:00
committed by GitHub
parent 14bada283b
commit 047ecdfd60
@@ -19,6 +19,14 @@ export default class PatchedJSDOMEnvironment extends JSDOMEnvironment {
const { global } = super(...args);
if (!global.TextEncoder) global.TextEncoder = TextEncoder;
if (!global.TextDecoder) global.TextDecoder = TextDecoder;
// TODO(sshah): Remove this once JSDOM provides structuredClone.
// https://github.com/jsdom/jsdom/issues/3363
if (!global.structuredClone) {
global.structuredClone = val => {
return JSON.parse(JSON.stringify(val));
};
}
}
}
export const TestEnvironment = PatchedJSDOMEnvironment;