tests.FetchAnswer
The handler's answer; a 200 with no body by default.
Usage
Return a fake network response.
// Return a fake network response.
import { Text, resource } from 'kuito';
import { assert, render, screen, test, type FetchAnswer } from 'kuito/tests';
function Weather() {
const forecast = resource(async () => {
const response = await fetch('https://api.example.com/forecast');
return response.ok ? 'Sunny' : `Unavailable (${response.status})`;
});
return <Text>{forecast.data.value ?? 'Loading'}</Text>;
}
const outage: FetchAnswer = { status: 503, body: 'Service unavailable' };
test('an outage shows as unavailable', async () => {
await render(<Weather />, { fetch: () => outage });
assert.ok(screen.getByText('Unavailable (503)'));
});Type declaration
export interface FetchAnswer {
status?: number;
headers?: Record<string, string>;
body?: string | Uint8Array;
}Members 3
| Name | Type | Required | Description |
|---|---|---|---|
status | number | No | — |
headers | Record<string, string> | No | — |
body | string | Uint8Array<ArrayBufferLike> | No | — |
Generated from the public TypeScript declarations: signatures, props and defaults come from the checked source, descriptions from its JSDoc. No defaults are invented.