CodeVetter · Repo Unpack · Behavior traces
testing-library/dom-testing-library
The following traces were reconstructed by reading callers and implementations, without executing them. They cover import-time initialization, synchronous lookup, asynchronous appearance and disappearance, event dispatch, configuration updates, and debugging. Branches such as absent global DOM, fake timers, pending promises, and query errors materially alter execution. The configuration trace describes in-memory state changes rather than a persistence service.
- Initialization: src/index.js imports the query modules; those modules construct variants with buildQueries; role-helpers initializes elementRoleList; screen then binds document.body or installs throwing query stubs when no global body exists.
- Required role lookup: screen.getByRole supplies the bound body → suggestion wrapper → makeSingleQuery → makeGetAllQuery → queryAllByRole → makeRoleSelector and filters; zero results use getMissingError/getElementError, and multiple results include matching-element diagnostics.
- Text lookup: getByText's generated getter calls queryAllByText → checkContainerType → makeNormalizer → getNodeText → matches/fuzzyMatches; successful cardinality checking returns the element, while missing text reports normalization/selector hints.
- Asynchronous appearance: findByTestId → makeFindQuery → waitForWrapper → asyncWrapper → waitFor; real timers observe mutations and poll, fake timers advance through unstable_advanceTimersWrapper, and checkCallback retries getter errors until success or handleTimeout.
- Disappearance: waitForElementToBeRemoved checks initial presence; direct elements become top-parent containment callbacks; waitFor retries while any remain, treats later TestingLibraryElementError as disappearance, and resolves undefined after removal.
- Input change: fireEvent.change → createEvent.change → createEvent merges defaults and target data → setNativeValue selects the prototype or own setter → node-owned Event construction → fireEvent → eventWrapper → dispatchEvent.
- Configuration update: configure accepts an object or calls a function with existing config, shallow-merges the delta into module state, and subsequent ByTestId calls read the new attribute through getTestIdAttribute; tests explicitly restore previous configuration.
- Debugging: screen.debug calls logDOM for one element or each array element → getUserCodeFrame → first non-node_modules stack frame → readFileSync/codeFrameColumns when available → prettyDOM → console.log; unavailable dependencies or unreadable files omit the source frame.