tests.Queries
Finds views as a user finds them, by their text or their role and accessible name.
Utilização
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);
});Declaração do tipo
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
| Nome | Tipo | Obrigatório | Descrição |
|---|---|---|---|
getByText | (text: TextMatch) => TestView | Sim | The one view showing text; throws when none or several do. |
getAllByText | (text: TextMatch) => TestView[] | Sim | — |
queryByText | (text: TextMatch) => TestView | null | Sim | — |
getByRole | (role: string, options?: RoleOptions) => TestView | Sim | The 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 | null | Sim | — |
getByText — assinaturas de método
Assinaturas
(text: TextMatch): TestViewParâmetros
| Nome | Tipo | Obrigatório | Descrição |
|---|---|---|---|
text | TextMatch | Sim | — |
Devolve
TestView
getAllByText — assinaturas de método
Assinaturas
(text: TextMatch): TestView[]Parâmetros
| Nome | Tipo | Obrigatório | Descrição |
|---|---|---|---|
text | TextMatch | Sim | — |
Devolve
TestView[]
queryByText — assinaturas de método
Assinaturas
(text: TextMatch): TestView | nullParâmetros
| Nome | Tipo | Obrigatório | Descrição |
|---|---|---|---|
text | TextMatch | Sim | — |
Devolve
TestView
getByRole — assinaturas de método
Assinaturas
(role: string, options?: RoleOptions): TestViewParâmetros
| Nome | Tipo | Obrigatório | Descrição |
|---|---|---|---|
role | string | Sim | — |
options | RoleOptions | Não | — |
Devolve
TestView
getAllByRole — assinaturas de método
Assinaturas
(role: string, options?: RoleOptions): TestView[]Parâmetros
| Nome | Tipo | Obrigatório | Descrição |
|---|---|---|---|
role | string | Sim | — |
options | RoleOptions | Não | — |
Devolve
TestView[]
queryByRole — assinaturas de método
Assinaturas
(role: string, options?: RoleOptions): TestView | nullParâmetros
| Nome | Tipo | Obrigatório | Descrição |
|---|---|---|---|
role | string | Sim | — |
options | RoleOptions | Nã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.