-
Notifications
You must be signed in to change notification settings - Fork 315
Expand file tree
/
Copy pathhappydom.test.ts
More file actions
45 lines (39 loc) · 1.2 KB
/
happydom.test.ts
File metadata and controls
45 lines (39 loc) · 1.2 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
37
38
39
40
41
42
43
44
45
import { afterAll, beforeAll, describe, expect, test } from "vitest";
import { GlobalRegistrator } from "@happy-dom/global-registrator";
describe("happydom", () => {
// Lazy import after setting up globals to apply happydom polyfills
let h3: typeof import("../src/index.ts");
beforeAll(async () => {
GlobalRegistrator.register({
url: "http://localhost:3000",
width: 1920,
height: 1080,
});
});
afterAll(async () => {
await GlobalRegistrator.unregister();
});
test("import h3", async () => {
h3 = await import("../src/index.ts");
});
test("render works", async () => {
const app = new h3.H3();
app.post("/", async (event) => {
return new Response(event.req.body, {
headers: event.req.headers,
});
});
const req = new Request("http://localhost:3000/", {
method: "POST",
body: JSON.stringify({ hello: "world" }),
headers: {
"Content-Type": "application/json",
},
});
const res = await app.fetch(req);
expect(res.status).toBe(200);
expect(res.headers.get("Content-Type")).toBe("application/json");
const json = await res.json();
expect(json).toEqual({ hello: "world" });
});
});