Skip to main content

Variable: userEvent

const userEvent: object

Defined in: user-event.ts:393

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:435
click()(element) => Promise<void>Activates a widget. Uses GTK's native Gtk.Widget.activate to trigger the widget's default action — clicking buttons, toggling checkboxes/switches, etc.user-event.ts:400
dblClick()(element) => Promise<void>Double-clicks a widget. Emits pressed/released signals with n_press=1, then n_press=2.user-event.ts:406
deselectOptions()(element, values) => Promise<void>Deselects options in a list. Works with ListBox and multi-selection list views.user-event.ts:453
hover()(element) => Promise<void>Simulates mouse entering a widget (hover). Triggers the "enter" signal on the widget's EventControllerMotion.user-event.ts:459
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:479
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:491
selectOptions()(element, values) => Promise<void>Selects options in a dropdown or list. Works with DropDown, ComboBox, ListBox, ListView, GridView, and ColumnView.user-event.ts:444
tab()(element, options?) => Promise<void>Simulates Tab key navigation.user-event.ts:419
tripleClick()(element) => Promise<void>Triple-clicks a widget. Emits pressed/released signals with n_press=1, 2, then 3. Useful for text selection.user-event.ts:412
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:429
unhover()(element) => Promise<void>Simulates mouse leaving a widget (unhover). Triggers the "leave" signal on the widget's EventControllerMotion.user-event.ts:465

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);
});