36 lines
1 KiB
TypeScript
36 lines
1 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import { app } from "../samples/hello-world/index.ts";
|
|
|
|
/**
|
|
* End to end test of the hello world sample: the routes are rendered by the
|
|
* application, without a http server in between.
|
|
*/
|
|
|
|
async function get(path: string): Promise<Response> {
|
|
return app.fetch(new Request(`http://localhost${path}`));
|
|
}
|
|
|
|
describe("hello world sample", () => {
|
|
test("renders the home page", async () => {
|
|
const response = await get("/");
|
|
expect(response.status).toBe(200);
|
|
const html = await response.text();
|
|
expect(html).toContain("<!DOCTYPE html>");
|
|
expect(html).toContain("Blog");
|
|
expect(html).toContain("Test1");
|
|
expect(html).toContain("Test2");
|
|
});
|
|
|
|
test("renders a single post", async () => {
|
|
const response = await get("/posts/test1");
|
|
expect(response.status).toBe(200);
|
|
const html = await response.text();
|
|
expect(html).toContain("Test1");
|
|
});
|
|
|
|
test("answers with 404 for unknown routes", async () => {
|
|
const response = await get("/nope");
|
|
expect(response.status).toBe(404);
|
|
});
|
|
|
|
});
|