diff --git a/CHANGELOG.md b/CHANGELOG.md index 2cdded6df47d..09a785d68a7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ ### Fixes +- `[jest-environment-node]` Add `atob` and `btoa` ([#12269](https://github.com/facebook/jest/pull/12269)) + ### Chore & Maintenance - `[*]` Update graceful-fs to ^4.2.9 ([#11749](https://github.com/facebook/jest/pull/11749)) diff --git a/packages/jest-environment-node/src/index.ts b/packages/jest-environment-node/src/index.ts index 385821e810d4..27b65b5add37 100644 --- a/packages/jest-environment-node/src/index.ts +++ b/packages/jest-environment-node/src/index.ts @@ -82,6 +82,11 @@ class NodeEnvironment implements JestEnvironment { if (typeof performance !== 'undefined') { global.performance = performance; } + // atob and btoa are global in Node >= 16 + if (typeof atob !== 'undefined' && typeof btoa !== 'undefined') { + global.atob = atob; + global.btoa = btoa; + } installCommonGlobals(global, config.globals); this.moduleMocker = new ModuleMocker(global);