Utilisation

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

Déclaration du type

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

Membres 6

NomTypeRequisDescription
getByText(text: TextMatch) => TestViewOuiThe one view showing text; throws when none or several do.
getAllByText(text: TextMatch) => TestView[]Oui—
queryByText(text: TextMatch) => TestView | nullOui—
getByRole(role: string, options?: RoleOptions) => TestViewOuiThe one view with role (and name, when given); throws when none or several have it.
getAllByRole(role: string, options?: RoleOptions) => TestView[]Oui—
queryByRole(role: string, options?: RoleOptions) => TestView | nullOui—
getByText — signatures de méthode

Signatures

ts
(text: TextMatch): TestView

Paramètres

NomTypeRequisDescription
textTextMatchOui—

Retourne

TestView

getAllByText — signatures de méthode

Signatures

ts
(text: TextMatch): TestView[]

Paramètres

NomTypeRequisDescription
textTextMatchOui—

Retourne

TestView[]

queryByText — signatures de méthode

Signatures

ts
(text: TextMatch): TestView | null

Paramètres

NomTypeRequisDescription
textTextMatchOui—

Retourne

TestView

getByRole — signatures de méthode

Signatures

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

Paramètres

NomTypeRequisDescription
rolestringOui—
optionsRoleOptionsNon—

Retourne

TestView

getAllByRole — signatures de méthode

Signatures

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

Paramètres

NomTypeRequisDescription
rolestringOui—
optionsRoleOptionsNon—

Retourne

TestView[]

queryByRole — signatures de méthode

Signatures

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

Paramètres

NomTypeRequisDescription
rolestringOui—
optionsRoleOptionsNon—

Retourne

TestView

Généré depuis les déclarations TypeScript publiques : signatures, props et valeurs par défaut viennent de la source vérifiée, les descriptions de sa JSDoc. Aucune valeur par défaut n'est inventée.