-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathjsdom-extended.js
More file actions
28 lines (22 loc) · 926 Bytes
/
jsdom-extended.js
File metadata and controls
28 lines (22 loc) · 926 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const {TestEnvironment: JSDOMEnvironment} = require('jest-environment-jsdom');
class JSDOMEnvironmentExtended extends JSDOMEnvironment {
constructor (...args) {
super(...args);
this.global.ReadableStream = global.ReadableStream || ReadableStream;
this.global.TextDecoder = global.TextDecoder || TextDecoder;
this.global.TextEncoder = global.TextEncoder || TextEncoder;
this.global.Blob = global.Blob || Blob;
this.global.Headers = global.Headers || Headers;
this.global.FormData = global.FormData || FormData;
this.global.Request = global.Request || Request;
this.global.Response = global.Response || Response;
// optional fetch polyfill if not defined
if (typeof this.global.fetch === 'undefined') {
this.global.fetch = fetch;
}
if (typeof this.global.structuredClone === 'undefined') {
this.global.structuredClone = structuredClone;
}
}
}
module.exports = JSDOMEnvironmentExtended;