Skip to content

API Reference / @gtkx/testing

@gtkx/testing ​

Namespaces ​

NamespaceDescription
prettyFormat-

Type Aliases ​

Type AliasDescription
BoundQueriesThe set of built-in queries (getBy, findBy, queryBy, and their All variants) bound to a specific container.
BuiltQueriesThe variants derived from one queryAllBy function, in the order DOM Testing Library returns them.
ByRoleOptionsOptions for role queries: an accessible name matcher plus accessible state and value constraints.
ByRoleValueConstraints on a widget's numeric range value used by role queries. The numbers come from the accessibility tree and match within 0.001, the resolution GTK keeps them to.
ClassExpectationThe expected value for a style class: an exact class name or a regular expression.
ConfigGlobal configuration for the testing harness, controlling query behavior, error formatting, and the timeouts used by async utilities and actionability checks.
ConfigFnFunction form of a configuration update: receives the current config and returns the fields to override.
ContainerA scope that queries and traversal can run against: a widget, an event controller, a layout manager, a list item or header, an application, or the sentinel representing all current toplevel windows.
ControllerConstructorAn event controller class that can be constructed without arguments, such as Gtk.GestureClick.
DragOffsetA drag offset relative to the drag start point.
DragOptionsOptions for a drag gesture: the starting point, the number of interpolated drag updates, or explicit intermediate offsets emitted before the final one.
DropContentThe value delivered to a drop target: a primitive (converted to a GObject.Value) or an explicit GObject.Value.
DropOptionsOptions for a drop: the drop coordinates within the target.
MatcherA value used to match widget text: a string or number, a regular expression, or a custom MatcherFunction.
MatcherFunctionA custom matcher predicate: given a candidate widget's normalized text content and the widget itself, returns whether it matches.
MatcherOptionsOptions controlling text matching and, for asynchronous queries, polling behavior.
MethodThe query family a suggestion targets.
MissingErrorBuilderBuilds the error thrown when a query that requires a match finds none.
MultipleErrorBuilderBuilds the error thrown when a single-match query finds more than one widget.
NormalizerFnNormalizes a widget's text before it is compared against a matcher.
NormalizerOptionsOptions controlling the default text normalizer.
PointerInputA pointer action token, as in Testing Library: a full click ([MouseLeft], [MouseRight], [MouseMiddle]), a button press ([MouseLeft>]) or a button release ([/MouseLeft]). click, down and up are the left button. The left button clicks the widget as click does; the right and middle buttons reach only the click gestures listening for them, such as a GtkGestureClick with button={Gdk.BUTTON_SECONDARY} that opens a context menu.
PrettyWidgetOptionsOptions controlling how a widget tree is rendered to a string by prettyWidget and logWidget.
QueryAllByThe queryAllBy function a query family is built from, taking the scope to search followed by the family's own matcher arguments. Its name determines the family name, so queryAllByTestId builds a TestId family.
QueryHelpersThe helpers used to build custom queries, bundled the way DOM Testing Library exposes them.
RenderHookOptionsOptions for renderHook: an optional wrapper and the initial props (required unless the props type permits undefined).
RenderHookResultThe result of renderHook: the latest hook return value plus functions to rerender with new props and to unmount.
RenderOptionsOptions for render: the container and base element to mount into, an optional wrapper, React behavior toggles, error callbacks, and custom queries to bind.
RenderResultThe result of a render call: queries scoped to the rendered tree, debug utilities, and controls for updating or tearing down the render.
ScreenThe global screen object's shape: built-in queries scoped to the current toplevels, plus debug utilities.
ScreenshotOptionsOptions for capturing a screenshot: the poll timeout and interval, a rendering scale factor, and a file to write the PNG to.
ScreenshotResultA captured screenshot: base64-encoded image data, its MIME type, and pixel dimensions.
ScrollDeltaA scroll distance in pixels along each axis.
SuggestionA suggested query for reaching a widget, including its family, variant, method name, and a toString that renders the full call.
TabOptionsOptions for userEvent.tab.
TextContentOptionsOptions controlling how toHaveTextContent normalizes the text it reads.
TextExpectationThe expected value for a text matcher: an exact string or a regular expression.
TypeOptionsOptions for userEvent.type.
UserEventUser interactions exposed by userEvent.
UserEventOptionsOptions shared by every helper on a UserEvent instance.
VariantThe query variant a suggestion targets.
WaitForOptionsOptions controlling how asynchronous queries and waits poll for a condition.
WidgetEventA signal emission built but not yet delivered. GObject has no event object to construct, so this records the target, signal, and arguments fireEvent will emit.
WidgetTypeA widget class usable as a query's as constraint, such as Gtk.Button. Abstract classes and generated GInterface pseudo-classes that extend Gtk.Accessible are accepted.
WrapperComponentA React component that wraps rendered content, receiving it as its children.

Variables ​

VariableDescription
actRuns a callback inside React's act environment, flushing pending state updates and effects, and resolves once the work has settled.
findAllByDisplayValueFinds all mapped widgets with a display value.
findAllByLabelTextFinds all mapped widgets with label text.
findAllByNameFinds all mapped widgets with a GTK name.
findAllByPlaceholderTextFinds all mapped widgets with placeholder text.
findAllByRoleFinds all mapped widgets with an accessible role.
findAllByTextFinds all mapped widgets with rendered text.
findByDisplayValueFinds one mapped widget by display value.
findByLabelTextFinds one mapped widget by label text.
findByNameFinds one mapped widget by GTK name.
findByPlaceholderTextFinds one mapped widget by placeholder text.
findByRoleFinds one mapped widget by accessible role.
findByTextFinds one mapped widget by rendered text.
getAllByDisplayValueGets all mapped widgets with a display value.
getAllByLabelTextGets all mapped widgets with label text.
getAllByNameGets all mapped widgets with a GTK name.
getAllByPlaceholderTextGets all mapped widgets with placeholder text.
getAllByRoleGets all mapped widgets with an accessible role.
getAllByTextGets all mapped widgets with rendered text.
getByDisplayValueGets one mapped widget by display value.
getByLabelTextGets one mapped widget by label text.
getByNameGets one mapped widget by GTK name.
getByPlaceholderTextGets one mapped widget by placeholder text.
getByRoleGets one mapped widget by accessible role.
getByTextGets one mapped widget by rendered text.
matchersThe widget assertion matchers keyed by name, suitable for passing to expect.extend.
queryByDisplayValueQueries one mapped widget by display value.
queryByLabelTextQueries one mapped widget by label text.
queryByNameQueries one mapped widget by GTK name.
queryByPlaceholderTextQueries one mapped widget by placeholder text.
queryByRoleQueries one mapped widget by accessible role.
queryByTextQueries one mapped widget by rendered text.
queryHelpersThe query-building helpers, bundled so they can be reached under a single import.
screenQueries and debug utilities bound to the most recent render, scoped to the current toplevel windows. Accessing it before any render throws.
userEventUser interactions that dispatch GTK events and gestures.

Functions ​

FunctionDescription
buildQueriesBuilds a query family from queryAllBy, following DOM Testing Library's buildQueries. Query suggestions use queryAllBy.name as the family name.
cleanupUnmounts every active render, quits the applications those renders started, and runs all registered cleanup callbacks, resetting the screen, the clipboard and the input the default userEvent still holds. Called automatically after each test.
computeHeadingLevelReturns the heading or hierarchy level GTK reports for a widget, or undefined when it declares none.
configureMerges the given overrides into the global testing configuration.
createEventRecords a signal emission without delivering it, so it can be inspected or held and passed to fireEvent later.
fireEventEmits a recorded signal emission inside React's act environment, so any resulting state updates are flushed before the promise resolves.
formatRoleConverts an accessible role enum value into its lowercase name, falling back to the numeric value when the role is unknown.
getAllControllersReturns every controller of the given type attached to a widget.
getConfigReturns the current global testing configuration.
getControllerReturns the first controller of the given type attached to a widget.
getDefaultNormalizerBuilds the default text normalizer, which optionally trims surrounding whitespace and collapses runs of whitespace into single spaces.
getElementErrorBuilds the error a failing query throws, appending the container's widget tree to the message the way the built-in queries do.
getQueriesForElementBinds the built-in queries, and any custom queries, to a specific container so they search only within that scope. Also exported as getQueriesForElement, which reads better in library code.
getRolesGroups every mapped widget in a container's tree by its accessible role name. Widgets that are not mapped are left out.
getSuggestedQueryComputes the recommended query for reaching the given widget, preferring role, then label text, placeholder text, text, display value, and name.
getWidgetTextReturns a widget's own text by trying its label, text, and title getters in order, then the contents it exposes through Gtk.AccessibleText, or null when none produce a value.
isInaccessibleReturns whether a widget is excluded from the accessibility tree, because it or one of its ancestors is marked hidden.
logRolesPrints the accessible roles in a container's tree to the console using prettyRoles.
logWidgetPrints one or more widget trees to the console using prettyWidget.
prettyRolesFormats the accessible roles in a container's tree as a readable string, listing each role together with its widgets and their accessible names. Widgets that are not mapped are left out.
prettyWidgetRenders a widget tree as an indented, HTML-like string showing each widget's tag, accessible attributes, and text content.
queryAllByDisplayValueFinds every widget whose current display value matches. Widgets that are not mapped are never matched.
queryAllByLabelTextFinds every widget associated with a label whose text matches: a Gtk.Label mnemonic target, the widget's own accessible label, or its labelled-by relation. Widgets that are not mapped are never matched.
queryAllByNameFinds every widget whose widget name matches. Widgets that are not mapped are never matched.
queryAllByObjectPropertyFinds every widget carrying a GObject property whose value matches, the counterpart of DOM Testing Library's queryAllByAttribute. The property name may be given in kebab-case or camelCase, and widgets that are not mapped are never matched.
queryAllByPlaceholderTextFinds every widget whose placeholder text matches. Widgets that are not mapped are never matched.
queryAllByRoleFinds every widget under the container whose accessible role matches role and that satisfies the given options. Widgets that are not mapped are never matched, and widgets excluded from the accessibility tree are skipped unless options.hidden is set. An Adwaita dialog matches once its content is shown, which libadwaita does a frame after the dialog opens.
queryAllByTextFinds every widget whose rendered text content matches. Widgets that are not mapped are never matched.
queryAllControllersReturns every controller of the given type attached to a widget, in the order GTK4 reports them.
queryByObjectPropertyReturns the single widget carrying a GObject property whose value matches, or null when none do, the counterpart of DOM Testing Library's queryByAttribute.
queryControllerReturns the first controller of the given type attached to a widget.
registerMatchersRegisters the widget matchers on the global expect, when one is available. Safe to call more than once.
renderRenders React into native widgets and returns queries, debug helpers, and lifecycle controls.
renderHookRenders a test component that calls the given hook, exposing its latest return value along with rerender and unmount controls.
screenshotCaptures a widget as PNG, retrying until it has a paintable size. Writes to options.path when supplied, creating missing parent directories.
waitForRepeatedly invokes a callback until it succeeds without throwing or the timeout elapses, retrying on each rejection at a fixed interval.
waitForElementToBeRemovedWaits until the given widget or widgets are detached from the tree. Rejects immediately if the target is already absent when called.

References ​

within ​

Renames and re-exports getQueriesForElement