Getting faster React Testing Library runs usually means tuning tests or buying bigger CI machines. A new project called @ctrl/dom takes another route: it replaces jsdom with a DOM that has Testing Library built in. On 100 small React test files it ran up to 5.2 times faster, and on Sentry’s real suite it saved 32% of the run time.
Its author earlier made one test file 43% faster through patches to jsdom and DOMSelector, most of which landed in jsdom 30.1.0. This project goes a step further by forking the DOM and the query layer as a pair.
Why stock Testing Library does so much work
Queries like getByRole mirror how a person uses a page, and because they stick to the DOM’s public API, the same tests run on jsdom, happy-dom or a browser. The price of that portability is zero shortcuts: each query goes through public calls.
Take getByRole(‘button’, { name: ‘Save’ }). The selector it runs also sweeps up every input on the page, and each match then gets its role, accessible name and visibility computed. Checking the role of one text input takes 12 matches() calls. A button takes 41 and a paragraph 96.
On a page of about 4,000 elements, locating one input costs the stock library 12,000 matches() calls and 2,007 getComputedStyle() calls. @ctrl/dom needs neither.

One object per node, cached answers
jsdom represents each node twice, as a generated wrapper around a hidden implementation object, so calls like getAttribute pass through the wrapper first. Every window also gets its own copy of those classes. @ctrl/dom gives every node one plain shape, NodeImpl. V8 can optimize property access on a single shape, and the classes are shared between windows. That matters for Vitest, which starts a new worker for each test file.
Memory use falls as well. The heap after a first test is 41 MB on jsdom and 16 MB on @ctrl/dom, and a Vitest worker ends a file at 171 MB versus 111 MB. Fewer objects means less garbage collection interrupting tests.
The bundled Testing Library reads those node objects directly. Elements get a numeric tag id when created, and role tables are arrays keyed by that id, built once at load. A document version number increases on every mutation, and while it stays the same, query results, accessible names, computed styles and live collections are served from cache. The stock library has no way to know the DOM is unchanged, so it recomputes everything.
A query is O(n) in both cases, since each makes one pass over the page. The saving is in the work done at each element.
Accidentally quadratic code
Some accidentally quadratic code got fixed too. A *ByRole candidate walked up every ancestor to judge visibility, so a single getByRole in a tree 1,000 levels deep took 6.1 ms. Stopping at the nearest styled ancestor brings that to 0.09 ms.
Another case: getAllByLabelText runs an [id=”x”] selector for each aria-labelledby element, and that form bypasses the id index. With 10,000 such elements a single query dropped from 720 ms to 14 ms.
Skipping the waiting
jsdom timers run on the wall clock, so findBy queries, waitFor and user-event all burn real milliseconds. Waiting made up 13% of test time in Sentry’s suite.
@ctrl/dom runs a virtual clock instead. Once a timer is the only thing left, it fires at once and Date.now() and performance.now() jump ahead to match. Order is preserved, so the app can’t notice. Setting timeSkip: false turns it off for a project or file.
What the numbers mean in practice
The 5.2x figure comes from 100 small test files that spend most of their time in the DOM and Testing Library. Real suites differ. Sentry’s tests load a huge app and render big component trees, so most time was never DOM time, and the saving was 32%. Profiling Base UI’s suite showed @ctrl/dom at about 10% of the run, with the remainder going to Node module loading and React.
It’s possible to keep stock Testing Library and replace only the DOM, which gave 1.3x to 3.6x in the synthetic runs. The rewritten queries account for most of the bigger gain.
Limits and how to try it
@ctrl/dom is built for React component tests and skips scripts, navigation, fetch, image loading, iframe src and real layout. It needs Node 26 or newer and React 19. Anything that relies on those features should stay on jsdom.
Installation is a package add and a Vitest plugin that redirects @testing-library imports to the @ctrl/dom builds. With testingLibrary: false the stock packages stay in place, which is slower but a gentler first step for tests that rely on stock behavior. Jest instructions are in the README.
The project is at 0.x, and its author expects your suite to find bugs. Reports are welcome, since the plan is to add more downstream projects to its test suites. A sensible trial is to run your suite before and after the switch and list the tests that fail only on @ctrl/dom.
Source: sigh.dev