From 926a001ef667219798c2d00563723f804f09a7b6 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 12 Dec 2024 17:26:28 -0700 Subject: [PATCH] Add polyfill for MessageChannel in getDataFromTree test --- config/jest.config.js | 5 +---- src/react/ssr/__tests__/getDataFromTree.test.tsx | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/config/jest.config.js b/config/jest.config.js index 29323d3da7..1e0d714b4a 100644 --- a/config/jest.config.js +++ b/config/jest.config.js @@ -29,10 +29,7 @@ const defaults = { const ignoreTSFiles = ".ts$"; const ignoreTSXFiles = ".tsx$"; -const react19TestFileIgnoreList = [ - ignoreTSFiles, - "src/react/ssr/__tests__/getDataFromTree.test.tsx", -]; +const react19TestFileIgnoreList = [ignoreTSFiles]; const react17TestFileIgnoreList = [ ignoreTSFiles, diff --git a/src/react/ssr/__tests__/getDataFromTree.test.tsx b/src/react/ssr/__tests__/getDataFromTree.test.tsx index 54bc53b4ac..0d2f8e2936 100644 --- a/src/react/ssr/__tests__/getDataFromTree.test.tsx +++ b/src/react/ssr/__tests__/getDataFromTree.test.tsx @@ -1,4 +1,19 @@ import React from "react"; + +if (React.version.startsWith("19")) { + // react-dom/server uses MessageChannel in React 19 + window.MessageChannel = jest.fn().mockImplementation(() => { + return { + port1: { + set onmessage(_cb: unknown) {}, + }, + port2: { + postMessage(_data: unknown) {}, + }, + }; + }); +} + import gql from "graphql-tag"; import { DocumentNode } from "graphql";