Utilização

Assert the request a screen sends.

tsx
// 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' });
});

Declaração do tipo

ts
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;
}

Membros 4

NomeTipoObrigatórioDescrição
urlstringSim—
methodstringSim—
headersRecord<string, string>Sim—
bodystringSimA text body as sent; null without one, or for one in bytes or a file.
Gerado a partir das declarações TypeScript públicas: assinaturas, props e predefinições vêm da fonte verificada, as descrições da sua JSDoc. Nenhuma predefinição é inventada.