import { act } from 'preact/test-utils'; import { ARIARole } from 'aria-query'; import { OptionsReceived } from 'pretty-format'; import * as prettyFormat from 'pretty-format'; export { act } export declare type AllByAttribute = ( attribute: string, container: HTMLElement, id: Matcher, options?: MatcherOptions, ) => HTMLElement[] export declare type AllByBoundAttribute = ( container: HTMLElement, id: Matcher, options?: MatcherOptions, ) => T[] export declare type AllByRole = ( container: HTMLElement, role: ByRoleMatcher, options?: ByRoleOptions, ) => T[] export declare type AllByText = ( container: HTMLElement, id: Matcher, options?: SelectorMatcherOptions, ) => T[] export declare type BoundFunction = T extends ( container: HTMLElement, ...args: infer P ) => infer R ? (...args: P) => R : never export declare type BoundFunctions = Q extends typeof queries ? { getByLabelText( ...args: Parameters>> ): ReturnType> getAllByLabelText( ...args: Parameters>> ): ReturnType> queryByLabelText( ...args: Parameters>> ): ReturnType> queryAllByLabelText( ...args: Parameters>> ): ReturnType> findByLabelText( ...args: Parameters>> ): ReturnType> findAllByLabelText( ...args: Parameters>> ): ReturnType> getByPlaceholderText( ...args: Parameters>> ): ReturnType> getAllByPlaceholderText( ...args: Parameters>> ): ReturnType> queryByPlaceholderText( ...args: Parameters>> ): ReturnType> queryAllByPlaceholderText( ...args: Parameters>> ): ReturnType> findByPlaceholderText( ...args: Parameters>> ): ReturnType> findAllByPlaceholderText( ...args: Parameters>> ): ReturnType> getByText( ...args: Parameters>> ): ReturnType> getAllByText( ...args: Parameters>> ): ReturnType> queryByText( ...args: Parameters>> ): ReturnType> queryAllByText( ...args: Parameters>> ): ReturnType> findByText( ...args: Parameters>> ): ReturnType> findAllByText( ...args: Parameters>> ): ReturnType> getByAltText( ...args: Parameters>> ): ReturnType> getAllByAltText( ...args: Parameters>> ): ReturnType> queryByAltText( ...args: Parameters>> ): ReturnType> queryAllByAltText( ...args: Parameters>> ): ReturnType> findByAltText( ...args: Parameters>> ): ReturnType> findAllByAltText( ...args: Parameters>> ): ReturnType> getByTitle( ...args: Parameters>> ): ReturnType> getAllByTitle( ...args: Parameters>> ): ReturnType> queryByTitle( ...args: Parameters>> ): ReturnType> queryAllByTitle( ...args: Parameters>> ): ReturnType> findByTitle( ...args: Parameters>> ): ReturnType> findAllByTitle( ...args: Parameters>> ): ReturnType> getByDisplayValue( ...args: Parameters>> ): ReturnType> getAllByDisplayValue( ...args: Parameters>> ): ReturnType> queryByDisplayValue( ...args: Parameters>> ): ReturnType> queryAllByDisplayValue( ...args: Parameters>> ): ReturnType> findByDisplayValue( ...args: Parameters>> ): ReturnType> findAllByDisplayValue( ...args: Parameters>> ): ReturnType> getByRole( ...args: Parameters>> ): ReturnType> getAllByRole( ...args: Parameters>> ): ReturnType> queryByRole( ...args: Parameters>> ): ReturnType> queryAllByRole( ...args: Parameters>> ): ReturnType> findByRole( ...args: Parameters>> ): ReturnType> findAllByRole( ...args: Parameters>> ): ReturnType> getByTestId( ...args: Parameters>> ): ReturnType> getAllByTestId( ...args: Parameters>> ): ReturnType> queryByTestId( ...args: Parameters>> ): ReturnType> queryAllByTestId( ...args: Parameters>> ): ReturnType> findByTestId( ...args: Parameters>> ): ReturnType> findAllByTestId( ...args: Parameters>> ): ReturnType> } & { [P in keyof Q]: BoundFunction } : { [P in keyof Q]: BoundFunction } export declare function buildQueries( queryAllBy: GetAllBy, getMultipleError: GetErrorFunction, getMissingError: GetErrorFunction, ): BuiltQueryMethods export declare type BuiltQueryMethods = [ QueryBy, GetAllBy, GetBy, FindAllBy, FindBy, ] export declare type ByRoleMatcher = ARIARole | (string & {}) export declare interface ByRoleOptions { /** suppress suggestions for a specific query */ suggest?: boolean /** * If true includes elements in the query set that are usually excluded from * the accessibility tree. `role="none"` or `role="presentation"` are included * in either case. */ hidden?: boolean /** * If true only includes elements in the query set that are marked as * selected in the accessibility tree, i.e., `aria-selected="true"` */ selected?: boolean /** * If true only includes elements in the query set that are marked as * busy in the accessibility tree, i.e., `aria-busy="true"` */ busy?: boolean /** * If true only includes elements in the query set that are marked as * checked in the accessibility tree, i.e., `aria-checked="true"` */ checked?: boolean /** * If true only includes elements in the query set that are marked as * pressed in the accessibility tree, i.e., `aria-pressed="true"` */ pressed?: boolean /** * Filters elements by their `aria-current` state. `true` and `false` match `aria-current="true"` and `aria-current="false"` (as well as a missing `aria-current` attribute) respectively. */ current?: boolean | string /** * If true only includes elements in the query set that are marked as * expanded in the accessibility tree, i.e., `aria-expanded="true"` */ expanded?: boolean /** * Includes elements with the `"heading"` role matching the indicated level, * either by the semantic HTML heading elements `

-

` or matching * the `aria-level` attribute. */ level?: number value?: { now?: number min?: number max?: number text?: Matcher } /** * Includes every role used in the `role` attribute * For example *ByRole('progressbar', {queryFallbacks: true})` will find
`. */ queryFallbacks?: boolean /** * Only considers elements with the specified accessible name. */ name?: | RegExp | string | ((accessibleName: string, element: Element) => boolean) /** * Only considers elements with the specified accessible description. */ description?: | RegExp | string | ((accessibleDescription: string, element: Element) => boolean) } /** * Cleanup elements rendered to the page and Preact trees that were mounted with render. * * @public */ export declare function cleanup(): void; export declare function computeHeadingLevel(element: Element): number | undefined export declare interface Config { testIdAttribute: string /** * WARNING: `unstable` prefix means this API may change in patch and minor releases. * @param cb */ unstable_advanceTimersWrapper(cb: (...args: unknown[]) => unknown): unknown // eslint-disable-next-line @typescript-eslint/no-explicit-any asyncWrapper(cb: (...args: any[]) => any): Promise // eslint-disable-next-line @typescript-eslint/no-explicit-any eventWrapper(cb: (...args: any[]) => any): void asyncUtilTimeout: number computedStyleSupportsPseudoElements: boolean defaultHidden: boolean /** default value for the `ignore` option in `ByText` queries */ defaultIgnore: string showOriginalStackTrace: boolean throwSuggestions: boolean getElementError: (message: string | null, container: Element) => Error } export declare interface ConfigFn { (existingConfig: Config): Partial } export declare function configure(configDelta: ConfigFn | Partial): void export declare const createEvent: CreateObject & CreateFunction; export declare type CreateFunction = ( eventName: string, node: Document | Element | Window | Node, init?: {}, options?: {EventType?: string; defaultInit?: {}}, ) => Event export declare type CreateObject = { [K in EventType_2]: ( element: Document | Element | Window | Node, options?: {}, ) => Event } export declare interface DefaultNormalizerOptions { trim?: boolean collapseWhitespace?: boolean } /** * @public * The lynx element tree */ export declare type ElementTree = ReturnType; /** * The Element PAPI Types * @public */ declare type ElementTreeGlobals = PickUnderscoreKeys; export declare type EventType = | 'focus' | 'blur' | 'scroll' | 'wheel' | 'tap' | 'longtap' | 'bgload' | 'bgerror' | 'touchstart' | 'touchmove' | 'touchcancel' | 'touchend' | 'longpress' | 'transitionstart' | 'transitioncancel' | 'transitionend' | 'animationstart' | 'animationiteration' | 'animationcancel' | 'animationend' | 'mousedown' | 'mouseup' | 'mousemove' | 'mouseclick' | 'mousedblclick' | 'mouselongpress' | 'keydown' | 'keyup' | 'layoutchange' | 'scrolltoupper' | 'scrolltolower' | 'scrollend' | 'contentsizechanged' | 'scrolltoupperedge' | 'scrolltoloweredge' | 'scrolltonormalstate'; declare type EventType_2 = | 'copy' | 'cut' | 'paste' | 'compositionEnd' | 'compositionStart' | 'compositionUpdate' | 'keyDown' | 'keyPress' | 'keyUp' | 'focus' | 'blur' | 'focusIn' | 'focusOut' | 'change' | 'input' | 'invalid' | 'submit' | 'reset' | 'click' | 'contextMenu' | 'dblClick' | 'drag' | 'dragEnd' | 'dragEnter' | 'dragExit' | 'dragLeave' | 'dragOver' | 'dragStart' | 'drop' | 'mouseDown' | 'mouseEnter' | 'mouseLeave' | 'mouseMove' | 'mouseOut' | 'mouseOver' | 'mouseUp' | 'popState' | 'select' | 'touchCancel' | 'touchEnd' | 'touchMove' | 'touchStart' | 'resize' | 'scroll' | 'wheel' | 'abort' | 'canPlay' | 'canPlayThrough' | 'durationChange' | 'emptied' | 'encrypted' | 'ended' | 'loadedData' | 'loadedMetadata' | 'loadStart' | 'pause' | 'play' | 'playing' | 'progress' | 'rateChange' | 'seeked' | 'seeking' | 'stalled' | 'suspend' | 'timeUpdate' | 'volumeChange' | 'waiting' | 'load' | 'error' | 'animationStart' | 'animationEnd' | 'animationIteration' | 'transitionCancel' | 'transitionEnd' | 'transitionRun' | 'transitionStart' | 'doubleClick' | 'pointerOver' | 'pointerEnter' | 'pointerDown' | 'pointerMove' | 'pointerUp' | 'pointerCancel' | 'pointerOut' | 'pointerLeave' | 'gotPointerCapture' | 'lostPointerCapture' | 'offline' | 'online' | 'pageHide' | 'pageShow' /** * @public */ declare type FilterUnderscoreKeys = { [K in keyof T]: K extends `__${string}` ? K : never; }[keyof T]; export declare type FindAllBy = QueryMethod< [Arguments[0], Arguments[1]?, waitForOptions?], Promise > export declare function findAllByAltText( ...args: Parameters> ): ReturnType> export declare type FindAllByBoundAttribute = ( container: HTMLElement, id: Matcher, options?: MatcherOptions, waitForElementOptions?: waitForOptions, ) => Promise export declare function findAllByDisplayValue( ...args: Parameters> ): ReturnType> export declare function findAllByLabelText( ...args: Parameters> ): ReturnType> export declare function findAllByPlaceholderText( ...args: Parameters> ): ReturnType> export declare type FindAllByRole = ( container: HTMLElement, role: ByRoleMatcher, options?: ByRoleOptions, waitForElementOptions?: waitForOptions, ) => Promise export declare function findAllByRole( ...args: Parameters> ): ReturnType> export declare function findAllByTestId( ...args: Parameters> ): ReturnType> export declare type FindAllByText = ( container: HTMLElement, id: Matcher, options?: SelectorMatcherOptions, waitForElementOptions?: waitForOptions, ) => Promise export declare function findAllByText( ...args: Parameters> ): ReturnType> export declare function findAllByTitle( ...args: Parameters> ): ReturnType> export declare type FindBy = QueryMethod< [Arguments[0], Arguments[1]?, waitForOptions?], Promise > export declare function findByAltText( ...args: Parameters> ): ReturnType> export declare type FindByBoundAttribute = ( container: HTMLElement, id: Matcher, options?: MatcherOptions, waitForElementOptions?: waitForOptions, ) => Promise export declare function findByDisplayValue( ...args: Parameters> ): ReturnType> export declare function findByLabelText( ...args: Parameters> ): ReturnType> export declare function findByPlaceholderText( ...args: Parameters> ): ReturnType> export declare type FindByRole = ( container: HTMLElement, role: ByRoleMatcher, options?: ByRoleOptions, waitForElementOptions?: waitForOptions, ) => Promise export declare function findByRole( ...args: Parameters> ): ReturnType> export declare function findByTestId( ...args: Parameters> ): ReturnType> export declare type FindByText = ( container: HTMLElement, id: Matcher, options?: SelectorMatcherOptions, waitForElementOptions?: waitForOptions, ) => Promise export declare function findByText( ...args: Parameters> ): ReturnType> export declare function findByTitle( ...args: Parameters> ): ReturnType> export declare const fireEvent: FireFunction & FireObject; export declare type FireFunction = ( element: Document | Element | Window | Node, event: Event, ) => boolean export declare type FireObject = { [K in EventType]: FireObject_2[EventType_2]; }; declare type FireObject_2 = { [K in EventType_2]: ( element: Document | Element | Window | Node, options?: {}, ) => boolean } export declare type GetAllBy = QueryMethod< Arguments, HTMLElement[] > export declare function getAllByAltText( ...args: Parameters> ): ReturnType> export declare function getAllByDisplayValue( ...args: Parameters> ): ReturnType> export declare function getAllByLabelText( ...args: Parameters> ): ReturnType> export declare function getAllByPlaceholderText( ...args: Parameters> ): ReturnType> export declare function getAllByRole( ...args: Parameters> ): ReturnType> export declare function getAllByTestId( ...args: Parameters> ): ReturnType> export declare function getAllByText( ...args: Parameters> ): ReturnType> export declare function getAllByTitle( ...args: Parameters> ): ReturnType> export declare type GetBy = QueryMethod export declare function getByAltText( ...args: Parameters> ): ReturnType> export declare type GetByBoundAttribute = ( container: HTMLElement, id: Matcher, options?: MatcherOptions, ) => T export declare function getByDisplayValue( ...args: Parameters> ): ReturnType> export declare function getByLabelText( ...args: Parameters> ): ReturnType> export declare function getByPlaceholderText( ...args: Parameters> ): ReturnType> export declare type GetByRole = ( container: HTMLElement, role: ByRoleMatcher, options?: ByRoleOptions, ) => T export declare function getByRole( ...args: Parameters> ): ReturnType> export declare function getByTestId( ...args: Parameters> ): ReturnType> export declare type GetByText = ( container: HTMLElement, id: Matcher, options?: SelectorMatcherOptions, ) => T export declare function getByText( ...args: Parameters> ): ReturnType> export declare function getByTitle( ...args: Parameters> ): ReturnType> export declare function getConfig(): Config export declare function getDefaultNormalizer( options?: DefaultNormalizerOptions, ): NormalizerFn export declare function getElementError( message: string | null, container: HTMLElement, ): Error export declare type GetErrorFunction = ( c: Element | null, ...args: Arguments ) => string export declare function getNodeText(node: HTMLElement): string export declare function getQueriesForElement< QueriesToBind extends Queries = typeof queries, // Extra type parameter required for reassignment. T extends QueriesToBind = QueriesToBind, >(element: HTMLElement, queriesToBind?: T): BoundFunctions export declare function getRoles(container: HTMLElement): { [index: string]: HTMLElement[] } export declare function getSuggestedQuery( element: HTMLElement, variant?: Variant, method?: Method, ): Suggestion | undefined /** * @public */ declare const initElementTree: () => { uniqueId2Element: Map; root: LynxElement | undefined; countElement(element: LynxElement, parentComponentUniqueId: number): void; __CreatePage(_tag: string, parentComponentUniqueId: number): LynxElement; __CreateRawText(text: string): LynxElement; __GetElementUniqueID(e: LynxElement): number; __SetClasses(e: LynxElement, cls: string): void; __CreateElement(tag: string, parentComponentUniqueId: number): LynxElement; __CreateView(parentComponentUniqueId: number): LynxElement; __CreateScrollView(parentComponentUniqueId: number): LynxElement; __FirstElement(e: LynxElement): LynxElement; __CreateText(parentComponentUniqueId: number): LynxElement; __CreateImage(parentComponentUniqueId: number): LynxElement; __CreateWrapperElement(parentComponentUniqueId: number): LynxElement; __AddInlineStyle(e: HTMLElement, key: number, value: string): void; __AppendElement(parent: LynxElement, child: LynxElement): void; __SetCSSId(e: LynxElement[] | LynxElement, id: string, entryName?: string | undefined): void; __SetAttribute(e: LynxElement, key: string, value: any): void; __AddEvent(e: LynxElement, eventType: string, eventName: string, eventHandler: string | Record): void; __GetEvent(e: LynxElement, eventType: string, eventName: string): { type: string; name: string; jsFunction: any; } | undefined; __SetID(e: LynxElement, id: string): void; __SetInlineStyles(e: LynxElement, styles: string | Record): void; __AddDataset(e: LynxElement, key: string, value: string): void; __SetDataset(e: LynxElement, dataset: any): void; __SetGestureDetector(e: LynxElement, id: number, type: number, config: any, relationMap: Record): void; __RemoveGestureDetector(e: LynxElement, id: number): void; __GetDataset(e: LynxElement): DOMStringMap; __RemoveElement(parent: LynxElement, child: LynxElement): void; __InsertElementBefore(parent: LynxElement, child: LynxElement, ref?: LynxElement | undefined): void; __ReplaceElement(newElement: LynxElement, oldElement: LynxElement): void; __FlushElementTree(): void; __UpdateListComponents(_list: LynxElement, _components: string[]): void; __UpdateListCallbacks(list: LynxElement, componentAtIndex: (list: LynxElement, listID: number, cellIndex: number, operationID: number, enable_reuse_notification: boolean) => void, enqueueComponent: (list: LynxElement, listID: number, sign: number) => void): void; __CreateList(parentComponentUniqueId: number, componentAtIndex: any, enqueueComponent: any): LynxElement; __GetTag(ele: LynxElement): string; __GetAttributeByName(ele: LynxElement, name: string): string | null; /** @internal */ animationMap: Map; __ElementAnimate(element: LynxElement, args: [number, string, ...any[]]): void; clear(): void; toTree(): LynxElement | undefined; /** * Enter a list-item element at the given index. * It will load the list-item element using the `componentAtIndex` callback. * * @param e - The list element * @param index - The index of the list-item element * @param args - The arguments used to create the list-item element * @returns The unique id of the list-item element */ enterListItemAtIndex(e: LynxElement, index: number, ...args: any[]): number; /** * Leave a list-item element. * It will mark the list-item element as unused using * the `enqueueComponent` callback, and the list-item element * will be reused in the future by other list-item elements. * * @param e - The list element * @param uiSign - The unique id of the list-item element */ leaveListItem(e: LynxElement, uiSign: number): void; toJSON(): LynxElement | undefined; __GetElementByUniqueId(uniqueId: number): LynxElement | undefined; }; /** * https://testing-library.com/docs/dom-testing-library/api-helpers#isinaccessible */ export declare function isInaccessible(element: Element): boolean export declare function logDOM( dom?: Element | HTMLDocument, maxLength?: number, options?: PrettyDOMOptions, ): void export declare function logRoles( container: HTMLElement, options?: LogRolesOptions, ): string export declare interface LogRolesOptions { hidden?: boolean } /** * Any Lynx Element, such as `view`, `text`, `image`, etc. * * {@link https://lynxjs.org/living-spec/index.html?ts=1743416098203#element%E2%91%A0 | Lynx Spec Reference} * * @public */ declare interface LynxElement extends HTMLElement { /** * The map of events bound to the element. */ eventMap?: { [key: string]: any; }; /** * The gestures bound to the element. */ gesture?: { [key: string]: any; }; /** * The cssId of the element */ cssId?: string; /** * Returns the first child. * * {@link https://developer.mozilla.org/docs/Web/API/Node/firstChild | MDN Reference} */ firstChild: LynxElement; /** * Returns the next sibling. * * {@link https://developer.mozilla.org/docs/Web/API/Node/nextSibling | MDN Reference} */ nextSibling: LynxElement; /** * Returns the parent. * * {@link https://developer.mozilla.org/docs/Web/API/Node/parentNode | MDN Reference} */ parentNode: LynxElement; } /** * The host environment used to initialize `LynxTestingEnv`. * * @public */ declare interface LynxEnv { window: Window & typeof globalThis; } /** * The `globalThis` object of Lynx dual thread environment. * * @public */ declare interface LynxGlobalThis { /** * The globalThis object. */ globalThis: LynxGlobalThis; [key: string]: any; } /** * A pure-JavaScript implementation of the {@link https://lynxjs.org/guide/spec.html | Lynx Spec}, * notably the {@link https://lynxjs.org/api/engine/element-api | Element PAPI} and {@link https://lynxjs.org/guide/spec#dual-threaded-model | Dual-threaded Model} for use with Node.js. * * @example * * ```ts * import { LynxTestingEnv } from '@lynx-js/testing-environment'; * import { JSDOM } from 'jsdom'; * * const lynxTestingEnv = new LynxTestingEnv({ window: new JSDOM().window }); * * lynxTestingEnv.switchToMainThread(); * // use the main thread Element PAPI * const page = __CreatePage('0', 0); * const view = __CreateView(0); * __AppendElement(page, view); * * ``` * * @public */ export declare class LynxTestingEnv { private originals; /** * The global object for the background thread. * * @example * * ```ts * import { LynxTestingEnv } from '@lynx-js/testing-environment'; * import { JSDOM } from 'jsdom'; * * const lynxTestingEnv = new LynxTestingEnv({ window: new JSDOM().window }); * * lynxTestingEnv.switchToBackgroundThread(); * // use the background thread global object * globalThis.lynxCoreInject.tt.OnLifecycleEvent(...args); * ``` */ backgroundThread: LynxGlobalThis; /** * The global object for the main thread. * * @example * * ```ts * import { LynxTestingEnv } from '@lynx-js/testing-environment'; * import { JSDOM } from 'jsdom'; * * const lynxTestingEnv = new LynxTestingEnv({ window: new JSDOM().window }); * * lynxTestingEnv.switchToMainThread(); * // use the main thread global object * const page = globalThis.__CreatePage('0', 0); * const view = globalThis.__CreateView(0); * globalThis.__AppendElement(page, view); * ``` */ mainThread: LynxGlobalThis & ElementTreeGlobals; env: LynxEnv; constructor(env?: LynxEnv); injectGlobals(): void; switchToBackgroundThread(): void; switchToMainThread(): void; clearGlobal(): void; reset(): void; } export declare type Match = ( textToMatch: string, node: HTMLElement | null, matcher: Matcher, options?: MatcherOptions, ) => boolean export declare type Matcher = MatcherFunction | RegExp | number | string export declare type MatcherFunction = ( content: string, element: Element | null, ) => boolean export declare interface MatcherOptions { exact?: boolean /** Use normalizer with getDefaultNormalizer instead */ trim?: boolean /** Use normalizer with getDefaultNormalizer instead */ collapseWhitespace?: boolean normalizer?: NormalizerFn /** suppress suggestions for a specific query */ suggest?: boolean } export declare type Method = | 'AltText' | 'alttext' | 'DisplayValue' | 'displayvalue' | 'LabelText' | 'labeltext' | 'PlaceholderText' | 'placeholdertext' | 'Role' | 'role' | 'TestId' | 'testid' | 'Text' | 'text' | 'Title' | 'title' export declare type NormalizerFn = (text: string) => string export declare interface NormalizerOptions extends DefaultNormalizerOptions { normalizer?: NormalizerFn } /** * @public */ declare type PickUnderscoreKeys = Pick>; export declare function prettyDOM( dom?: Element | HTMLDocument, maxLength?: number, options?: PrettyDOMOptions, ): string | false export declare interface PrettyDOMOptions extends prettyFormat.OptionsReceived { /** * Given a `Node` return `false` if you wish to ignore that node in the output. * By default, ignores `