From 5b66289aa38eebf3e4984ca6f021b0429b301f5b Mon Sep 17 00:00:00 2001 From: Jay Phelps Date: Tue, 3 Aug 2021 16:36:03 -0700 Subject: [PATCH] fix(jest-environment-node): Add Event and EventTarget to node global environment Fixes #11705 --- CHANGELOG.md | 2 ++ packages/jest-environment-node/src/index.ts | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a6b1d88a6a8d..652eb15fbe26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ ### Fixes +- `[jest-environment-node]` Add `Event` and `EventTarget` to node global environment. ([#11705](https://github.com/facebook/jest/issues/11705)) + ### Chore & Maintenance ### Performance 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);