-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathjest.setup.js
More file actions
36 lines (30 loc) · 987 Bytes
/
jest.setup.js
File metadata and controls
36 lines (30 loc) · 987 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
29
30
31
32
33
34
35
36
require('@testing-library/jest-dom');
// Mock Next.js server globals for API route tests
global.Request = class MockRequest {
constructor(input, init = {}) {
this.url = input;
this.method = init.method || 'GET';
this.headers = new Map(Object.entries(init.headers || {}));
this.body = init.body;
}
async json() {
return typeof this.body === 'string' ? JSON.parse(this.body) : this.body;
}
async text() {
return typeof this.body === 'string' ? this.body : JSON.stringify(this.body);
}
};
global.Response = class MockResponse {
constructor(body, init = {}) {
this.body = body;
this.status = init.status || 200;
this.statusText = init.statusText || 'OK';
this.headers = new Map(Object.entries(init.headers || {}));
}
async json() {
return typeof this.body === 'string' ? JSON.parse(this.body) : this.body;
}
async text() {
return typeof this.body === 'string' ? this.body : JSON.stringify(this.body);
}
};