tests.FetchRequest
A request the app's fetch sent, as the test's handler receives it.
Usage
Assert the request a screen sends.
// Assert the request a screen sends.
import { Button } from 'kuito';
import { assert, press, render, screen, test, type FetchRequest } from 'kuito/tests';
const Subscribe = () => (
<Button
onPress={() =>
void fetch('https://api.example.com/subscribe', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ plan: 'yearly' }),
})
}
>
Subscribe
</Button>
);
test('subscribing posts the plan', async () => {
const sent: FetchRequest[] = [];
await render(<Subscribe />, {
fetch: (request) => {
sent.push(request);
return { status: 204 };
},
});
await press(screen.getByText('Subscribe'));
assert.equal(sent[0]?.method, 'POST');
assert.deepEqual(JSON.parse(sent[0]?.body ?? ''), { plan: 'yearly' });
});Type declaration
export interface FetchRequest {
url: string;
method: string;
headers: Record<string, string>;
/** A text body as sent; null without one, or for one in bytes or a file. */
body: string | null;
}Members 4
| Name | Type | Required | Description |
|---|---|---|---|
url | string | Yes | — |
method | string | Yes | — |
headers | Record<string, string> | Yes | — |
body | string | Yes | A text body as sent; null without one, or for one in bytes or a file. |
Generated from the public TypeScript declarations: signatures, props and defaults come from the checked source, descriptions from its JSDoc. No defaults are invented.