MockEndpointAPIProviderclass

new MockEndpointAPIProvider<P, R, C>(handlers: EndpointHandlers<C>, context: C, source?: ClientAPIProvider<P, R>)
ParamType
handlersEndpointHandlers<C>
A collection of endpoint handlers that can be matched and invoked by handleEndpoints(). required
contextC
required
sourceClientAPIProvider<P, R>
A client-side API provider that sends requests over the network using fetch().
Return
MockEndpointAPIProvider<P, R, C>
Provider that mocks an API that calls and matches an array of EndpointHandler objects returned from Endpoint.handler()

Provider that mocks an API that calls and matches an array of EndpointHandler objects returned from Endpoint.handler()

  • Used to test server-side API code, calls against an API made up of multiple Endpoint instances.

A MockAPIProvider that wires the mock transport directly to a real EndpointHandler array. Client code calls endpoints exactly as in production, but each call is dispatched to its handler in the same process — so you can test client and server logic together without a network.

The constructor takes the handlers array, a context value passed to every handler, and an optional source provider.

Usage

ts
import { MockEndpointAPIProvider } from "shelving/api"

const handlers = [
  getUser.handler(async ({ id }) => ({ id, name: "Alice", email: "[email protected]" })),
]

const api = new MockEndpointAPIProvider(handlers, undefined)

const user = await api.call(getUser, { id: "u_1" })
// user == { id: "u_1", name: "Alice", email: "[email protected]" }

console.log(api.requestCalls) // inspect recorded calls