forked from kriasoft/react-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathecho.test.ts
29 lines (25 loc) · 803 Bytes
/
echo.test.ts
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
/* SPDX-FileCopyrightText: 2014-present Kriasoft */
/* SPDX-License-Identifier: MIT */
import { expect, test } from "vitest";
import { handler } from "./echo.js";
test("GET /echo", async () => {
// Initialize an HTTP GET request object
const env = getMiniflareBindings();
const req = new Request(`https://${env.APP_HOSTNAME}/echo`);
req.headers.set("Content-Type", "application/json");
// Fetch the target URL and parse the response
const res = await handler.fetch(req, env);
const body = await res
.json()
.catch(() => res.text())
.catch(() => undefined);
// Compare the response with the expected result
expect({ status: res.status, body }).toEqual({
status: 200,
body: {
headers: {
"content-type": "application/json",
},
},
});
});