Verwendung

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

Typdeklaration

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

Mitglieder 6

NameTypErforderlichBeschreibung
getByText(text: TextMatch) => TestViewJaThe one view showing text; throws when none or several do.
getAllByText(text: TextMatch) => TestView[]Ja—
queryByText(text: TextMatch) => TestView | nullJa—
getByRole(role: string, options?: RoleOptions) => TestViewJaThe one view with role (and name, when given); throws when none or several have it.
getAllByRole(role: string, options?: RoleOptions) => TestView[]Ja—
queryByRole(role: string, options?: RoleOptions) => TestView | nullJa—
getByText — Methodensignaturen

Signaturen

ts
(text: TextMatch): TestView

Parameter

NameTypErforderlichBeschreibung
textTextMatchJa—

Rückgabe

TestView

getAllByText — Methodensignaturen

Signaturen

ts
(text: TextMatch): TestView[]

Parameter

NameTypErforderlichBeschreibung
textTextMatchJa—

Rückgabe

TestView[]

queryByText — Methodensignaturen

Signaturen

ts
(text: TextMatch): TestView | null

Parameter

NameTypErforderlichBeschreibung
textTextMatchJa—

Rückgabe

TestView

getByRole — Methodensignaturen

Signaturen

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

Parameter

NameTypErforderlichBeschreibung
rolestringJa—
optionsRoleOptionsNein—

Rückgabe

TestView

getAllByRole — Methodensignaturen

Signaturen

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

Parameter

NameTypErforderlichBeschreibung
rolestringJa—
optionsRoleOptionsNein—

Rückgabe

TestView[]

queryByRole — Methodensignaturen

Signaturen

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

Parameter

NameTypErforderlichBeschreibung
rolestringJa—
optionsRoleOptionsNein—

Rückgabe

TestView

Generiert aus den öffentlichen TypeScript-Deklarationen: Signaturen, Props und Standardwerte stammen aus der geprüften Quelle, Beschreibungen aus deren JSDoc. Kein Standardwert ist erfunden.