Utilização

Scope queries to part of a screen.

tsx
// Scope queries to part of a screen.
import { Text, VStack } from 'kuito';
import { assert, render, screen, test, within, type Queries } from 'kuito/tests';

const Card = (props: { title: string; status: string }) => (
  <VStack>
    <Text>{props.title}</Text>
    <Text>{props.status}</Text>
  </VStack>
);

// The same queries over the whole screen or inside one view.
const cardOf = (scope: Queries, title: string) => scope.getByText(title).parent;

test('each card shows its own status', async () => {
  await render(
    <VStack>
      <Card title="Backup" status="Done" />
      <Card title="Sync" status="Running" />
    </VStack>,
  );

  const sync = cardOf(screen, 'Sync');

  assert.ok(sync);
  assert.ok(within(sync).getByText('Running'));
  assert.equal(within(sync).queryByText('Done'), null);
});

Declaração do tipo

ts
export interface Queries {
  /** The one view showing `text`; throws when none or several do. */
  getByText(text: TextMatch): TestView;
  getAllByText(text: TextMatch): TestView[];
  queryByText(text: TextMatch): TestView | null;
  /** The one view with `role` (and `name`, when given); throws when none or several have it. */
  getByRole(role: string, options?: RoleOptions): TestView;
  getAllByRole(role: string, options?: RoleOptions): TestView[];
  queryByRole(role: string, options?: RoleOptions): TestView | null;
}

Membros 6

NomeTipoObrigatórioDescrição
getByText(text: TextMatch) => TestViewSimThe one view showing text; throws when none or several do.
getAllByText(text: TextMatch) => TestView[]Sim—
queryByText(text: TextMatch) => TestView | nullSim—
getByRole(role: string, options?: RoleOptions) => TestViewSimThe one view with role (and name, when given); throws when none or several have it.
getAllByRole(role: string, options?: RoleOptions) => TestView[]Sim—
queryByRole(role: string, options?: RoleOptions) => TestView | nullSim—
getByText — assinaturas de método

Assinaturas

ts
(text: TextMatch): TestView

Parâmetros

NomeTipoObrigatórioDescrição
textTextMatchSim—

Devolve

TestView

getAllByText — assinaturas de método

Assinaturas

ts
(text: TextMatch): TestView[]

Parâmetros

NomeTipoObrigatórioDescrição
textTextMatchSim—

Devolve

TestView[]

queryByText — assinaturas de método

Assinaturas

ts
(text: TextMatch): TestView | null

Parâmetros

NomeTipoObrigatórioDescrição
textTextMatchSim—

Devolve

TestView

getByRole — assinaturas de método

Assinaturas

ts
(role: string, options?: RoleOptions): TestView

Parâmetros

NomeTipoObrigatórioDescrição
rolestringSim—
optionsRoleOptionsNão—

Devolve

TestView

getAllByRole — assinaturas de método

Assinaturas

ts
(role: string, options?: RoleOptions): TestView[]

Parâmetros

NomeTipoObrigatórioDescrição
rolestringSim—
optionsRoleOptionsNão—

Devolve

TestView[]

queryByRole — assinaturas de método

Assinaturas

ts
(role: string, options?: RoleOptions): TestView | null

Parâmetros

NomeTipoObrigatórioDescrição
rolestringSim—
optionsRoleOptionsNão—

Devolve

TestView

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.