tests.Queries
Finds views as a user finds them, by their text or their role and accessible name.
Verwendung
Scope queries to part of a screen.
// 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
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
| Name | Typ | Erforderlich | Beschreibung |
|---|---|---|---|
getByText | (text: TextMatch) => TestView | Ja | The one view showing text; throws when none or several do. |
getAllByText | (text: TextMatch) => TestView[] | Ja | — |
queryByText | (text: TextMatch) => TestView | null | Ja | — |
getByRole | (role: string, options?: RoleOptions) => TestView | Ja | The 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 | null | Ja | — |
getByText — Methodensignaturen
Signaturen
(text: TextMatch): TestViewParameter
| Name | Typ | Erforderlich | Beschreibung |
|---|---|---|---|
text | TextMatch | Ja | — |
Rückgabe
TestView
getAllByText — Methodensignaturen
Signaturen
(text: TextMatch): TestView[]Parameter
| Name | Typ | Erforderlich | Beschreibung |
|---|---|---|---|
text | TextMatch | Ja | — |
Rückgabe
TestView[]
queryByText — Methodensignaturen
Signaturen
(text: TextMatch): TestView | nullParameter
| Name | Typ | Erforderlich | Beschreibung |
|---|---|---|---|
text | TextMatch | Ja | — |
Rückgabe
TestView
getByRole — Methodensignaturen
Signaturen
(role: string, options?: RoleOptions): TestViewParameter
| Name | Typ | Erforderlich | Beschreibung |
|---|---|---|---|
role | string | Ja | — |
options | RoleOptions | Nein | — |
Rückgabe
TestView
getAllByRole — Methodensignaturen
Signaturen
(role: string, options?: RoleOptions): TestView[]Parameter
| Name | Typ | Erforderlich | Beschreibung |
|---|---|---|---|
role | string | Ja | — |
options | RoleOptions | Nein | — |
Rückgabe
TestView[]
queryByRole — Methodensignaturen
Signaturen
(role: string, options?: RoleOptions): TestView | nullParameter
| Name | Typ | Erforderlich | Beschreibung |
|---|---|---|---|
role | string | Ja | — |
options | RoleOptions | Nein | — |
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.