feat: centralize application framework primitives
This commit is contained in:
1 parent
96e082b943
commit
a3ddd39b7b
73 files changed
+1429
-84
No files matched your search
@@ -1,4 +1,12 @@
|
||||
import { test, expect, renderComponent, mountHtml, callRoute } from "../src/index.ts";
|
||||
import {
|
||||
test,
|
||||
expect,
|
||||
renderComponent,
|
||||
mountHtml,
|
||||
callRoute,
|
||||
createFetchMock,
|
||||
createTestContext,
|
||||
} from "../src/index.ts";
|
||||
|
||||
const COUNTER = `component Counter {
|
||||
props {
|
||||
@@ -30,3 +38,22 @@ test("callRoute invokes an API handler with a Context", async () => {
|
||||
expect(res.status).toBe(200);
|
||||
expect(await res.json()).toEqual({ ok: true, path: "/api/ping", method: "POST" });
|
||||
});
|
||||
|
||||
test("createTestContext installs route params, locals and a user without casts", () => {
|
||||
const user = { id: "u1" };
|
||||
const ctx = createTestContext("/items/42", {
|
||||
params: { id: "42" },
|
||||
user,
|
||||
locals: { trace: "test" },
|
||||
});
|
||||
expect(ctx.params.id).toBe("42");
|
||||
expect(ctx.user).toBe(user);
|
||||
expect(ctx.locals.trace).toBe("test");
|
||||
});
|
||||
|
||||
test("createFetchMock is fluent and compatible with Bun fetch", async () => {
|
||||
const fetchMock: typeof fetch = createFetchMock().respondOnce(Response.json({ ok: true }));
|
||||
const response = await fetchMock("https://example.test/token");
|
||||
expect(await response.json()).toEqual({ ok: true });
|
||||
expect(typeof fetchMock.preconnect).toBe("function");
|
||||
});
|
||||
Reference in new issue
Block a user