Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/deno_mock_fetch/mock-fetch.ts>MockFetch

Deno mock fetch implementation
Latest
class MockFetch
import { MockFetch } from "https://deno.land/x/deno_mock_fetch@1.0.1/mock-fetch.ts";

Deno Mock Fetch class.

Instantiate this to set up global fetch API interception.

Constructors

new
MockFetch()

Properties

readonly
calls: number

The total number of times Mock Fetch has been called.

readonly
isMockActive

Indicator for whether MockFetch is active or not.

Methods

Deactivate Mock Fetch, restoring current state.

Activate Net Connect support.

close(): void

Upon close, cleanup

Deactivate Mock Fetch, preserving current state.

Deactivate Net Connect support.

Intercept a global fetch API call for the defined inputs.

import { MockFetch } from "https://deno.land/x/deno_mock_fetch@1.0.1/mod.ts";

const mockFetch = new MockFetch();
mockFetch
  // Intercept `GET https://example.com/hello`
  .intercept("https://example.com/hello", { method: "GET" })
  // Response with status `200` and text `hello`
  .response("hello", { status: 200 });