forked from SudiptaPaul-31/Codely
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.ts
More file actions
36 lines (33 loc) · 1.08 KB
/
Copy pathjest.setup.ts
File metadata and controls
36 lines (33 loc) · 1.08 KB
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
import { TextEncoder, TextDecoder } from "util";
// Polyfill TextEncoder and TextDecoder in jsdom test environment
if (typeof global.TextEncoder === "undefined") {
global.TextEncoder = TextEncoder;
}
if (typeof global.TextDecoder === "undefined") {
(global as any).TextDecoder = TextDecoder;
}
// Polyfill fetch and Response if missing
if (typeof global.fetch === "undefined") {
global.fetch = jest.fn() as any;
}
if (typeof global.Response === "undefined") {
(global as any).Response = class Response {
body: any;
status: number;
ok: boolean;
constructor(body?: any, init?: any) {
this.body = body;
this.status = init?.status || 200;
this.ok = this.status >= 200 && this.status < 300;
}
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);
}
};
}
// Dummy environment variable for tests
process.env.DATABASE_URL =
process.env.DATABASE_URL || "postgres://dummy:dummy@localhost:5432/dummy";