Skip to main content

Variable: screen

const screen: object

Defined in: screen.ts:65

Global query object for accessing rendered components.

Provides the same query methods as render result, but automatically uses the most recently rendered application as the container.

Type Declaration

NameTypeDescriptionDefined in
debug()() => voidPrint the widget tree to console for debuggingscreen.ts:68
findAllByLabelText()(text, options?) => Promise<Widget[]>Find all elements by label/text content (waits and throws if none found)types.ts:126
findAllByRole()(role, options?) => Promise<Widget[]>Find all elements by accessible role (waits and throws if none found)types.ts:124
findAllByTestId()(testId, options?) => Promise<Widget[]>Find all elements by test ID (waits and throws if none found)types.ts:130
findAllByText()(text, options?) => Promise<Widget[]>Find all elements by visible text (waits and throws if none found)types.ts:128
findByLabelText()(text, options?) => Promise<Widget>Find single element by label/text content (waits and throws if not found)types.ts:118
findByRole()(role, options?) => Promise<Widget>Find single element by accessible role (waits and throws if not found)types.ts:116
findByTestId()(testId, options?) => Promise<Widget>Find single element by test ID (waits and throws if not found)types.ts:122
findByText()(text, options?) => Promise<Widget>Find single element by visible text (waits and throws if not found)types.ts:120
logRoles()() => voidLog all accessible roles to console for debuggingscreen.ts:72
queryAllByLabelText()(text, options?) => Widget[]Query all elements by label/text content (returns empty array if none found)types.ts:110
queryAllByRole()(role, options?) => Widget[]Query all elements by accessible role (returns empty array if none found)types.ts:108
queryAllByTestId()(testId, options?) => Widget[]Query all elements by test ID (returns empty array if none found)types.ts:114
queryAllByText()(text, options?) => Widget[]Query all elements by visible text (returns empty array if none found)types.ts:112
queryByLabelText()(text, options?) => Widget | nullQuery single element by label/text content (returns null if not found)types.ts:102
queryByRole()(role, options?) => Widget | nullQuery single element by accessible role (returns null if not found)types.ts:100
queryByTestId()(testId, options?) => Widget | nullQuery single element by test ID (returns null if not found)types.ts:106
queryByText()(text, options?) => Widget | nullQuery single element by visible text (returns null if not found)types.ts:104
screenshot()(selector?, options?) => Promise<ScreenshotResult>Capture a screenshot of the application window, saving it to a temporary file and logging the file path. Throws Error if no windows are available or no matching window is found Example await screen.screenshot(); // First window await screen.screenshot(0); // Window at index 0 await screen.screenshot("Settings"); // Window with title containing "Settings" await screen.screenshot(/^My App/); // Window with title matching regexscreen.ts:92

Example

import { render, screen } from "@gtkx/testing";

test("finds button", async () => {
await render(<MyComponent />);
const button = await screen.findByRole(Gtk.AccessibleRole.BUTTON);
expect(button).toBeDefined();
});

See