Testing Library

Testing Library Query Playground

Paste a small DOM snapshot, compare Testing Library-style queries and see exactly when getBy, queryBy and AllBy variants pass, return null, return an empty array or throw.

  • DOM stays in the browser
  • Query priority guide
  • Variant semantics

Choose the query before the test becomes brittle

Testing Library pushes tests toward user-visible behavior: roles, labels, text, display values and accessible names before implementation details. This playground gives code review a small, inspectable surface for checking what each query family and variant would do in a sanitized HTML snapshot.

The evaluator uses a detached DOMParser document, removes risky markup and never sends pasted HTML, query text or matched content to a backend.

Compare query families and variants

Choose a preset or paste markup, then switch query family, variant, role and exact matching to inspect result semantics.

Run query

Review role, label, placeholder and display value behavior in a normal sign-in form. Throws when there is no match or when multiple elements match.Best default when the element exposes a meaningful role and accessible name.

DOM and query inputs

Query result

Run a query to see variant semantics, matched elements, diagnostics and a copyable Testing Library snippet.

Testing Library query review guide

Start with user-visible contracts

Role and accessible name usually describe what the user can perceive. Labels, text and display values come before data-testid when the UI exposes a real semantic handle.

Variant choice changes failure behavior

getBy is strict and loud, queryBy is useful for absence checks, and AllBy variants make repeated UI explicit. The same DOM can be correct or failing depending on that choice.

This is an educational safe subset

The playground does not import DOM Testing Library at runtime, does not execute RegExp input and does not simulate delayed async DOM updates for findBy.

Query selection often sits next to locator review, matcher semantics and rule testing.

FAQ

Does this import DOM Testing Library package?

No. The MVP uses a small browser-only evaluator that mirrors common query semantics without adding the full package to the public bundle.

Why can queryBy throw?

queryBy returns null only for no match. Like getBy, it still throws when more than one element matches.

Are RegExp queries supported?

Not in the runtime evaluator. Plain strings keep the playground predictable and avoid ReDoS-style input risks.

Does pasted HTML leave the browser?

No. The DOM snapshot is parsed and sanitized locally and is not sent to a backend.