Skip to main content
Latest
variable mf.mock
import { mf } from "https://deno.land/x/jwfetch@v1.3.1/test_deps.ts";
const { mock } = mf;

Mock a new route, or override an existing handler.

The route uses path-to-regexp syntax, with the additional extension of (optional) method routing (prefix with METHOD@, eg. POST@/user/:id).

The handler function can either be a function or an async function.

mock("GET@/users/:id", async (_req, match) => {
  const id = parseInt(match.params["id"]);
  const data = await magicallyGetMyUserData(id);
  return new Response(JSON.stringify(data));
})