-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathtest.setup.ts
More file actions
28 lines (24 loc) · 864 Bytes
/
test.setup.ts
File metadata and controls
28 lines (24 loc) · 864 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
// Add custom jest matchers from jest-dom
import '@testing-library/jest-dom';
// Polyfill Response for Node.js test environment
if (typeof global.Response === 'undefined') {
global.Response = class Response {
constructor(public body: any, public init?: ResponseInit) {}
status = this.init?.status || 200;
statusText = this.init?.statusText || '';
headers = {
entries: () => Object.entries(this.init?.headers || {}),
get: (key: string) => {
const headers = this.init?.headers || {};
const value = (headers as any)[key];
return value !== undefined ? value : null;
},
};
async text() {
return typeof this.body === 'string' ? this.body : JSON.stringify(this.body);
}
async json() {
return typeof this.body === 'string' ? JSON.parse(this.body) : this.body;
}
} as any;
}