Skip to content

Commit 160d27a

Browse files
chyzwarSimenB
authored andcommitted
Added missing TextEncoder and TextDecoder to jest-envirotment-node (#8022)
1 parent c3a0167 commit 160d27a

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
### Fixes
1616

17+
- `[jest-environment-node]` Add mising globals: TextEncoder and TextDecoder ([#8022](https://github.com/facebook/jest/pull/8022))
1718
- `[jest-cli]` Fix prototype pollution vulnerability in dependency ([#7904](https://github.com/facebook/jest/pull/7904))
1819
- `[jest-cli]` Refactor `-o` and `--coverage` combined ([#7611](https://github.com/facebook/jest/pull/7611))
1920
- `[expect]` Fix custom async matcher stack trace ([#7652](https://github.com/facebook/jest/pull/7652))

packages/jest-environment-node/src/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ class NodeEnvironment implements JestEnvironment {
4242
global.URL = URL;
4343
global.URLSearchParams = URLSearchParams;
4444
}
45+
// TextDecoder and TextDecoder are global in Node >= 11
46+
if (
47+
typeof TextEncoder !== 'undefined' &&
48+
typeof TextDecoder !== 'undefined'
49+
) {
50+
/* global TextEncoder, TextDecoder */
51+
global.TextEncoder = TextEncoder;
52+
global.TextDecoder = TextDecoder;
53+
}
4554
installCommonGlobals(global, config.globals);
4655
this.moduleMocker = new ModuleMocker(global);
4756

0 commit comments

Comments
 (0)