File tree Expand file tree Collapse file tree 3 files changed +26
-0
lines changed Expand file tree Collapse file tree 3 files changed +26
-0
lines changed Original file line number Diff line number Diff line change 1
1
require ( 'zone.js' ) ;
2
2
require ( 'zone.js/testing' ) ;
3
+ const { TextEncoder, TextDecoder } = require ( 'util' ) ;
4
+
3
5
const { getTestBed } = require ( '@angular/core/testing' ) ;
4
6
const {
5
7
BrowserDynamicTestingModule,
6
8
platformBrowserDynamicTesting,
7
9
} = require ( '@angular/platform-browser-dynamic/testing' ) ;
8
10
11
+ if ( typeof globalThis . TextEncoder === 'undefined' ) {
12
+ globalThis . TextEncoder = TextEncoder ;
13
+ globalThis . TextDecoder = TextDecoder ;
14
+ }
15
+
9
16
const testEnvironmentOptions = globalThis . ngJest ?. testEnvironmentOptions ?? Object . create ( null ) ;
10
17
11
18
getTestBed ( ) . initTestEnvironment ( BrowserDynamicTestingModule , platformBrowserDynamicTesting ( ) , testEnvironmentOptions ) ;
Original file line number Diff line number Diff line change @@ -2,6 +2,12 @@ import 'zone.js';
2
2
import 'zone.js/testing' ;
3
3
import { getTestBed } from '@angular/core/testing' ;
4
4
import { BrowserDynamicTestingModule , platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing' ;
5
+ import { TextEncoder , TextDecoder } from 'util' ;
6
+
7
+ if ( typeof globalThis . TextEncoder === 'undefined' ) {
8
+ globalThis . TextEncoder = TextEncoder ;
9
+ globalThis . TextDecoder = TextDecoder ;
10
+ }
5
11
6
12
const testEnvironmentOptions = globalThis . ngJest ?. testEnvironmentOptions ?? Object . create ( null ) ;
7
13
Original file line number Diff line number Diff line change @@ -47,6 +47,7 @@ describe('setup-jest', () => {
47
47
48
48
beforeEach ( ( ) => {
49
49
delete globalThis . ngJest ;
50
+ delete globalThis . TextEncoder ;
50
51
jest . clearAllMocks ( ) ;
51
52
jest . resetModules ( ) ;
52
53
} ) ;
@@ -78,6 +79,12 @@ describe('setup-jest', () => {
78
79
errorOnUnknownProperties : true ,
79
80
} ) ;
80
81
} ) ;
82
+
83
+ test ( 'should always have TextEncoder in globalThis' , async ( ) => {
84
+ await import ( '../../setup-jest' ) ;
85
+
86
+ expect ( globalThis . TextEncoder ) . toBeDefined ( ) ;
87
+ } ) ;
81
88
} ) ;
82
89
83
90
describe ( 'for ESM setup-jest, test environment initialization' , ( ) => {
@@ -107,5 +114,11 @@ describe('setup-jest', () => {
107
114
errorOnUnknownProperties : true ,
108
115
} ) ;
109
116
} ) ;
117
+
118
+ test ( 'should always have TextEncoder in globalThis' , async ( ) => {
119
+ await import ( '../../setup-jest.mjs' ) ;
120
+
121
+ expect ( globalThis . TextEncoder ) . toBeDefined ( ) ;
122
+ } ) ;
110
123
} ) ;
111
124
} ) ;
You can’t perform that action at this time.
0 commit comments