Skip to main content
Module

x/mock_fetch/mod.ts>mock

An extremely simple way to mock globalThis.fetch responses
Latest
variable mock
import { mock } from "https://deno.land/x/mock_fetch@0.3.0/mod.ts";

Mock a new route, or override an existing handler.

The route uses URLPattern syntax, with the additional extension of (optional) method routing by prefixing with the method, eg. "POST@/user/:id".

The handler function may be asynchronous.

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