diff --git a/CHANGELOG.md b/CHANGELOG.md index 10517c26bc96..3b17a52932b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ ### Fixes +- `[jest-environment-node]` Add mising globals: TextEncoder and TextDecoder ([#8022](https://github.com/facebook/jest/pull/8022)) - `[jest-cli]` Fix prototype pollution vulnerability in dependency ([#7904](https://github.com/facebook/jest/pull/7904)) - `[jest-cli]` Refactor `-o` and `--coverage` combined ([#7611](https://github.com/facebook/jest/pull/7611)) - `[expect]` Fix custom async matcher stack trace ([#7652](https://github.com/facebook/jest/pull/7652)) diff --git a/packages/jest-environment-node/src/index.ts b/packages/jest-environment-node/src/index.ts index b0b10569374d..bc82af123b5e 100644 --- a/packages/jest-environment-node/src/index.ts +++ b/packages/jest-environment-node/src/index.ts @@ -42,6 +42,15 @@ class NodeEnvironment implements JestEnvironment { global.URL = URL; global.URLSearchParams = URLSearchParams; } + // TextDecoder and TextDecoder are global in Node >= 11 + if ( + typeof TextEncoder !== 'undefined' && + typeof TextDecoder !== 'undefined' + ) { + /* global TextEncoder, TextDecoder */ + global.TextEncoder = TextEncoder; + global.TextDecoder = TextDecoder; + } installCommonGlobals(global, config.globals); this.moduleMocker = new ModuleMocker(global);