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:24
software.versionpublicstring-src/wellknown.ts:25
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:230

Methods ​

allCalls() ​

ts
allCalls(): RecordedCall[];

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

Every request this instance received, in order.

For "nothing was sent" claims: asserting a specific route was never called can't fail if the client has no way to call it, whereas comparing this list before and after an action genuinely checks that the action stayed local.

Returns ​

RecordedCall[]


calls() ​

ts
calls(matcher): RecordedCall[];

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

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:217

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:264

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:302

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:329

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:334

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:345

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:380

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>