Skip to main content

Variable: userEvent

const userEvent: object

Defined in: user-event.ts:383

User interaction utilities for testing.

Simulates user actions like clicking, typing, and selecting. All methods are async and wait for GTK event processing.

Type Declaration

NameTypeDescriptionDefined in
clear()(element) => Promise<void>Clears an editable widget's content. Sets the text to empty string.user-event.ts:425
click()(element) => Promise<void>Clicks or toggles a widget. For toggleable widgets (checkboxes, switches, toggle buttons), toggles the active state. For buttons, emits clicked signal.user-event.ts:390
dblClick()(element) => Promise<void>Double-clicks a widget. Emits two consecutive clicked signals.user-event.ts:396
deselectOptions()(element, values) => Promise<void>Deselects options in a list. Works with ListBox and multi-selection list views.user-event.ts:443
hover()(element) => Promise<void>Simulates mouse entering a widget (hover). Triggers the "enter" signal on the widget's EventControllerMotion.user-event.ts:449
keyboard()(element, input) => Promise<void>Simulates keyboard input. Supports special keys in braces: {Enter}, {Tab}, {Escape}, etc. Use {Key>} to hold a key down, {/Key} to release. Example await userEvent.keyboard(element, "hello"); await userEvent.keyboard(element, "{Enter}"); await userEvent.keyboard(element, "{Shift>}A{/Shift}");user-event.ts:469
pointer()(element, input) => Promise<void>Simulates pointer (mouse) input. Supports: "click", "[MouseLeft]", "down", "up". Example await userEvent.pointer(element, "click"); await userEvent.pointer(element, "[MouseLeft]");user-event.ts:481
selectOptions()(element, values) => Promise<void>Selects options in a dropdown or list. Works with DropDown, ComboBox, ListBox, ListView, GridView, and ColumnView.user-event.ts:434
tab()(element, options?) => Promise<void>Simulates Tab key navigation.user-event.ts:409
tripleClick()(element) => Promise<void>Triple-clicks a widget. Emits three consecutive clicked signals. Useful for text selection.user-event.ts:402
type()(element, text) => Promise<void>Types text into an editable widget. Appends text to the current content. Works with Entry, SearchEntry, and SpinButton widgets.user-event.ts:419
unhover()(element) => Promise<void>Simulates mouse leaving a widget (unhover). Triggers the "leave" signal on the widget's EventControllerMotion.user-event.ts:455

Example

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

test("form submission", async () => {
await render(<LoginForm />);

const input = await screen.findByRole(Gtk.AccessibleRole.TEXT_BOX);
await userEvent.type(input, "username");

const button = await screen.findByRole(Gtk.AccessibleRole.BUTTON);
await userEvent.click(button);
});