From 51613c5d0aee2ecd826a350dbd5db178ea01309a Mon Sep 17 00:00:00 2001 From: aarush130 Date: Fri, 30 Jan 2026 14:02:41 +0530 Subject: [PATCH] fix: resolve Jest test execution failures (#121) - Fix TextEncoder/TextDecoder not defined error by importing from Node's util module - Add npm overrides to pin cheerio to 1.0.0-rc.12 for enzyme compatibility - Fixes jsdom polyfill issues and cheerio module structure changes --- package.json | 5 +++++ test/CustomTestEnvironment.js | 17 +++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 42894fa..99fbefa 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,11 @@ "@babel/runtime": "7.16.7", "classnames": "2.3.1" }, + "overrides": { + "enzyme": { + "cheerio": "1.0.0-rc.12" + } + }, "devDependencies": { "@babel/cli": "7.19.3", "@babel/core": "7.26.0", diff --git a/test/CustomTestEnvironment.js b/test/CustomTestEnvironment.js index f995049..bf256f0 100644 --- a/test/CustomTestEnvironment.js +++ b/test/CustomTestEnvironment.js @@ -1,12 +1,21 @@ const TestEnvironment = require('jest-environment-jsdom'); +const {TextEncoder, TextDecoder} = require('util'); module.exports = class CustomTestEnvironment extends TestEnvironment { async setup() { await super.setup(); + // Polyfill TextEncoder/TextDecoder for jsdom environment this.global.TextEncoder = TextEncoder; this.global.TextDecoder = TextDecoder; - this.global.Response = Response; - this.global.Request = Request; - this.global.ReadableStream = ReadableStream; + // These are available in Node.js 18+ globals + if (typeof Response !== 'undefined') { + this.global.Response = Response; + } + if (typeof Request !== 'undefined') { + this.global.Request = Request; + } + if (typeof ReadableStream !== 'undefined') { + this.global.ReadableStream = ReadableStream; + } } -}; \ No newline at end of file +};