Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Latest
function createFreshContext
import { createFreshContext } from "https://deno.land/x/fresh_testing_library@0.13.0/internal/fresh/context.ts";

Returns

FreshContext<Record<string, unknown>, unknown>

Type Parameters

optional
TData = unknown
optional
TState extends Record<string, unknown> = Record<string, unknown>

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);

Type Parameters

optional
TData = unknown
optional
TState = Record<string, unknown>

Parameters

request: Request
optional
options: Partial<CreateFreshContextOptions<TData, TState>>