import { createFreshContext } from "https://deno.land/x/fresh_testing_library@0.13.1/internal/fresh/context.ts";
Parameters
request: Request
Returns
FreshContext<Record<string, unknown>, unknown>
Parameters
optional
options: Partial<CreateFreshContextOptions<TData, TState>>This function creates FreshContext
which can be passed directly to fresh handlers, middlewares, routes, etc.
If CreateFreshContextOptions.manifest
is specified, FreshContext.params
and a route to be rendered by FreshContext.render
is automatically inferred from Request.url
.
import { createFreshContext } from "$fresh-testing-library/server.ts";
import { handler } from "$/routes/api/users/[id].ts";
import manifest from "$/fresh.gen.ts";
import { assertExists } from "$std/assert/assert_exists.ts";
import { assertEquals } from "$std/assert/assert_equals.ts";
const request = new Request("http://localhost:8000/api/users/34");
const ctx = createFreshContext(request, { manifest });
assertEquals(ctx.params, { id: "34" });
assertExists(handler.GET);
const response = await handler.GET(request, ctx);
Parameters
request: Request
optional
options: Partial<CreateFreshContextOptions<TData, TState>>