Skip to content

Class: FakeInstance

Defined in: src/testing/FakeInstance.ts:148

Extended by

Constructors

Constructor

ts
new FakeInstance(options): FakeInstance;

Defined in: src/testing/FakeInstance.ts:165

Parameters

ParameterType
optionsFakeInstanceOptions

Returns

FakeInstance

Properties

PropertyModifierTypeDescriptionDefined in
hostreadonlystring-src/testing/FakeInstance.ts:149
originreadonlystring-src/testing/FakeInstance.ts:151
softwarereadonlyobject-src/testing/FakeInstance.ts:153
software.namepublicstring-src/wellknown.ts:19
software.versionpublicstring-src/wellknown.ts:20
fetchreadonly{ (input, init?): Promise<Response>; (input, init?): Promise<Response>; }fetch-compatible adapter. Prefer clientOptions() when constructing a ThreadiverseClient; use this directly to install a global fetch mock. Unrouted requests and { abort } responses throw TypeError, like a real network failure.src/testing/FakeInstance.ts:218

Methods

calls()

ts
calls(matcher): RecordedCall[];

Defined in: src/testing/FakeInstance.ts:189

All recorded requests matching "METHOD /path" (query ignored).

Parameters

ParameterType
matcher| `POST /${string}` | `DELETE /${string}` | `GET /${string}` | `PUT /${string}`

Returns

RecordedCall[]


clientOptions()

ts
clientOptions(): ThreadiverseClientOptions;

Defined in: src/testing/FakeInstance.ts:205

Options for a ThreadiverseClient scoped to this fake: routes fetch through the instance and isolates software discovery from the process-global cache (so multiple fakes for the same host — e.g. different versions across tests — can't contaminate each other).

ts
const client = new ThreadiverseClient(fake.origin, fake.clientOptions());

Returns

ThreadiverseClientOptions


handle()

ts
handle(request): Promise<FakeResponse | undefined>;

Defined in: src/testing/FakeInstance.ts:252

Resolve a request against the route table.

Returns undefined for requests to other origins (callers decide whether to pass those through). Unmocked same-origin requests are answered with a loud 404 instead of escaping to the real network.

Parameters

ParameterType
requestFakeRequest

Returns

Promise<FakeResponse | undefined>


install()

ts
install(page): Promise<void>;

Defined in: src/testing/FakeInstance.ts:290

Install onto a Playwright page. Routes all traffic for this instance's origin; other origins are untouched.

Parameters

ParameterType
pagePageLike

Returns

Promise<void>


mock()

ts
mock(matcher, responder): void;

Defined in: src/testing/FakeInstance.ts:317

Set (or replace) the response for an endpoint. Last call wins.

Parameters

ParameterType
matcher| `POST /${string}` | `DELETE /${string}` | `GET /${string}` | `PUT /${string}`
responderResponder

Returns

void


mockOnce()

ts
mockOnce(matcher, responder): void;

Defined in: src/testing/FakeInstance.ts:322

Respond once for an endpoint, then fall back to the standing mock.

Parameters

ParameterType
matcher| `POST /${string}` | `DELETE /${string}` | `GET /${string}` | `PUT /${string}`
responderResponder

Returns

void


waitForCall()

ts
waitForCall(
   matcher, 
   predicate?, 
__namedParameters?): Promise<RecordedCall>;

Defined in: src/testing/FakeInstance.ts:333

Wait until a matching request is recorded, then return the latest. Resolution is push-based (no polling), so pending waiters settle the moment the request lands — only the timeout path needs real timers.

Parameters

ParameterType
matcher| `POST /${string}` | `DELETE /${string}` | `GET /${string}` | `PUT /${string}`
predicate(call) => boolean
__namedParameters{ timeoutMs?: number; }
__namedParameters.timeoutMs?number

Returns

Promise<RecordedCall>


buildOperationApi()

ts
protected buildOperationApi<Ops>(operations, renderError): OperationApi<Ops>;

Defined in: src/testing/FakeInstance.ts:368

Build the operation-level API (on/once/callsTo/waitForPayload) from a provider's operation definitions plus its error wire renderer.

Type Parameters

Type Parameter
Ops extends Record<string, OperationDef<unknown>>

Parameters

ParameterType
operationsOps
renderError(error) => FakeResponse

Returns

OperationApi<Ops>