CodeVetter · Repo Unpack · Data flow
testing-library/dom-testing-library
Query inputs consist of a container, matcher, and options; family-specific candidate selection feeds shared matching and cardinality wrappers. Elements remain owned by the consumer DOM, and results are references or promises for references. Event creation can mutate those elements before dispatch, while asynchronous utilities own transient observation and retry state. Error and debugging boundaries convert DOM/source content into strings, console output, or encoded URLs.
- getQueriesForElement reduces a function map into functions bound with the container as their first argument, mutating the supplied initialValue object when one is provided.
- Text lookup validates the container, selects container/descendant candidates, removes ignored nodes, extracts getNodeText, normalizes the string, and applies the exact or fuzzy matcher.
- Label lookup gathers label metadata through getRealLabels/getLabels, combines label content and aria-label matches, then deduplicates element references and filters by selector.
- Role lookup builds a CSS selector from explicit role tokens and aria-query tag relations, then filters role identity, ordered state conditions, accessible name/description, and accessibility; ancestor exclusion results are cached per call.
- Shared wrappers turn candidate arrays into null, an element, arrays, or exceptions; optional suggestion checks run after successful lookup, and makeFindQuery passes the getter plus container/options to waitFor.
- waitFor owns lastError, promiseStatus, finished, timer IDs, and an observer; callback rejection allows later retries, pending promises block overlapping callbacks, and normal completion clears timers and disconnects the real-timer observer.
- Event initialization merges registry defaults and caller data, applies native value/file/target mutations to the node, constructs an event using its window, installs transfer properties, and returns dispatchEvent's result through eventWrapper.
- getElementError embeds prettyDOM output in an exception; logDOM additionally requests a stack-derived source frame; logTestingPlaygroundURL separately compresses raw innerHTML into a URL fragment and logs/returns it.