tests.Queries
Finds views as a user finds them, by their text or their role and accessible name.
Utilisation
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);
});Déclaration du type
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
| Nom | Type | Requis | Description |
|---|---|---|---|
getByText | (text: TextMatch) => TestView | Oui | The one view showing text; throws when none or several do. |
getAllByText | (text: TextMatch) => TestView[] | Oui | — |
queryByText | (text: TextMatch) => TestView | null | Oui | — |
getByRole | (role: string, options?: RoleOptions) => TestView | Oui | The 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 | null | Oui | — |
getByText — signatures de méthode
Signatures
(text: TextMatch): TestViewParamètres
| Nom | Type | Requis | Description |
|---|---|---|---|
text | TextMatch | Oui | — |
Retourne
TestView
getAllByText — signatures de méthode
Signatures
(text: TextMatch): TestView[]Paramètres
| Nom | Type | Requis | Description |
|---|---|---|---|
text | TextMatch | Oui | — |
Retourne
TestView[]
queryByText — signatures de méthode
Signatures
(text: TextMatch): TestView | nullParamètres
| Nom | Type | Requis | Description |
|---|---|---|---|
text | TextMatch | Oui | — |
Retourne
TestView
getByRole — signatures de méthode
Signatures
(role: string, options?: RoleOptions): TestViewParamètres
| Nom | Type | Requis | Description |
|---|---|---|---|
role | string | Oui | — |
options | RoleOptions | Non | — |
Retourne
TestView
getAllByRole — signatures de méthode
Signatures
(role: string, options?: RoleOptions): TestView[]Paramètres
| Nom | Type | Requis | Description |
|---|---|---|---|
role | string | Oui | — |
options | RoleOptions | Non | — |
Retourne
TestView[]
queryByRole — signatures de méthode
Signatures
(role: string, options?: RoleOptions): TestView | nullParamètres
| Nom | Type | Requis | Description |
|---|---|---|---|
role | string | Oui | — |
options | RoleOptions | Non | — |
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.