faultyFetch
faultyFetch(
inner,options): {(input,init?):Promise<Response>; (input,init?):Promise<Response>; }
Defined in: src/testing/index.ts:175
Wraps a fetch so some calls fail on purpose, for tests of how a client copes.
Each call that match accepts (all of them, by default) takes two draws from the
generator, in this order: first one that decides whether the call gets a fault
(draw < rate), then one that picks which of faults. Both are always taken, so the
pick sequence doesn’t shift when rate changes. A call match rejects takes none.
With a seed, the sequence is the same every run.
latencyMs uses the global setTimeout at call time, so fake timers work, and waits its
full length even past the 2^31 - 1 ms a plain timer allows. Both waits end with the signal’s
reason as soon as the request’s signal aborts, and any fault rejects with it at once when the
signal is already aborted.
Parameters
Section titled “Parameters”{(input, init?): Promise<Response>; (input, init?): Promise<Response>; }
options
Section titled “options”Returns
Section titled “Returns”(
input,init?):Promise<Response>
Parameters
Section titled “Parameters”URL | RequestInfo
RequestInit
Returns
Section titled “Returns”Promise<Response>
(
input,init?):Promise<Response>
Parameters
Section titled “Parameters”string | URL | Request
RequestInit
Returns
Section titled “Returns”Promise<Response>
Example
Section titled “Example”const client = HttpClient.create({ fetch: faultyFetch(fetch, { faults: [{ status: 503, retryAfter: 1 }], seed: 42, rate: 0.5 }),});Throws
Section titled “Throws”when inner or options is invalid, including headers a
Response would refuse.
