From b65a1d8c5ebd7efcc63b1b2e24efb9541076dd2c Mon Sep 17 00:00:00 2001 From: Jay Phelps Date: Fri, 13 Aug 2021 08:12:00 -0700 Subject: [PATCH] fix(jest-environment-node): Add Event and EventTarget to node global (#11727) --- CHANGELOG.md | 1 + packages/jest-environment-node/src/index.ts | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd6a007e0b4e..5ebd5b93c387 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Fixes - `[jest-types]` Compat with `@types/node` v16 ([#11645](https://github.com/facebook/jest/pull/11645)) +- `[jest-environment-node]` Add `Event` and `EventTarget` to node global environment. ([#11705](https://github.com/facebook/jest/issues/11705)) ### Chore & Maintenance diff --git a/packages/jest-environment-node/src/index.ts b/packages/jest-environment-node/src/index.ts index ebf6d4648e4f..26f336b0cd52 100644 --- a/packages/jest-environment-node/src/index.ts +++ b/packages/jest-environment-node/src/index.ts @@ -66,6 +66,14 @@ class NodeEnvironment implements JestEnvironment { if (typeof AbortController !== 'undefined') { global.AbortController = AbortController; } + // Event is global in Node >= 15.4 + if (typeof Event !== 'undefined') { + global.Event = Event; + } + // EventTarget is global in Node >= 15.4 + if (typeof EventTarget !== 'undefined') { + global.EventTarget = EventTarget; + } installCommonGlobals(global, config.globals); this.moduleMocker = new ModuleMocker(global);