npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

test-renderer

v1.3.1

Published

A lightweight test renderer for React and a modern replacement for the deprecated React Test Renderer.

Readme

Test Renderer for React

A lightweight test renderer for React and a modern replacement for the deprecated React Test Renderer.

This library is used by React Native Testing Library but should work with any React variant.

It uses React Reconciler to build a custom renderer that operates on host elements by default, and provides escape hatches for complex use-cases. Most React Reconciler options are exposed through RootOptions.

For release and compatibility policy, see docs/versioning.md.

Installation

yarn add -D test-renderer

Getting Started

import { createRoot } from "test-renderer";
import { act } from "react";

test("renders a component", async () => {
  const renderer = createRoot();

  // Use `act` in async mode to allow resolving all scheduled React updates
  await act(async () => {
    renderer.render(<div>Hello!</div>);
  });

  expect(renderer.container).toMatchInlineSnapshot(`
    <>
      <div>
        Hello!
      </div>
    </>
  `);
});

Documentation

Test Output Tree

Instead of producing a DOM tree or a native view hierarchy, the renderer builds an in-memory Test Output Tree:

  • Composed of TestNodes, where each node is either:
    • A TestInstance: represents a host element such as div or View
    • A plain string: represents a text node
  • The root is accessible via root.container, a TestInstance whose type is an empty string
  • TestInstance nodes are traversable and queryable; see the TestInstance API

JSON Output Tree

Calling toJSON() on a TestInstance produces a JSON Output Tree, a static, plain-object snapshot of the Test Output Tree at that point in time:

  • Composed of JsonNodes, where each node is either:
    • A JsonElement: a plain object with type, props, and children
    • A plain string: a text node
  • Contains no live references, making it safe to serialize
  • Ideal for snapshot testing

API Reference

createRoot(options?)

Creates a new test renderer root instance.

Parameters:

  • options (optional): Configuration options for the renderer. See RootOptions below.

Returns: A Root object with the following properties:

  • render(element: ReactElement): Renders a React element into the root. Fragments are supported. Non-element root values such as strings or null are not supported. Must be called within act().
  • unmount(): Unmounts the root and cleans up. Must be called within act().
  • container: A TestInstance wrapper that contains the rendered element(s). Use this to query and inspect the rendered tree.

Example:

const renderer = createRoot();
await act(async () => {
  renderer.render(<div>Hello!</div>);
});

RootOptions

Optional configuration passed to createRoot. Common options:

  • textComponentTypes / publicTextComponentTypes: Host component types allowed to contain text nodes (useful for simulating React Native's text rendering rules).
  • isStrictMode: Enable React Strict Mode.
  • identifierPrefix: Prefix for IDs generated by useId().
  • onCaughtError / onUncaughtError / onRecoverableError: Error-handling callbacks.

The full options table, along with the TestInstance and QueryOptions APIs, is in the API Reference.

License

MIT