Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. Preact
  3. Preact Render Spy

Preact Render Spy

ISCJavaScriptv1.3.0

A testing utility for Preact components that provides virtual DOM access and an enzyme-like API.

Visit WebsiteGitHubGitHub
178 stars24 forks0 contributors

What is Preact Render Spy?

preact-render-spy is a testing utility for Preact components that allows developers to render components and inspect the resulting virtual DOM. It solves the problem of testing Preact components in isolation or full depth by providing an API similar to Enzyme, with methods to find elements, simulate events, and assert on component state and output.

Target Audience

Preact developers who need to write unit and integration tests for their components, especially those familiar with Enzyme's testing patterns or looking for a Preact-specific testing solution.

Value Proposition

Developers choose preact-render-spy because it's tailored for Preact, offers both shallow and deep rendering, integrates with Jest snapshots, and provides a straightforward API for testing component behavior and lifecycle methods without requiring a full DOM environment.

Overview

Render preact components with access to the produced virtual dom for testing.

Use Cases

Best For

  • Testing Preact component rendering and virtual DOM structure
  • Writing unit tests with shallow rendering for component isolation
  • Simulating user interactions like clicks and event handlers
  • Testing component lifecycle methods such as componentWillReceiveProps
  • Integrating with Jest for snapshot testing of Preact components
  • Migrating Enzyme-based tests to a Preact-specific testing utility

Not Ideal For

  • Projects built with React instead of Preact, as it's specifically designed for Preact components
  • Teams requiring full Enzyme feature compatibility for advanced testing scenarios like complex selector nesting or extensive plugin ecosystems
  • Applications needing real browser testing or integration with end-to-end frameworks like Cypress or Selenium
  • Large-scale projects with strict TypeScript support or demand for extensive, commercially-backed documentation

Pros & Cons

Pros

Dual Rendering Strategies

Offers both shallow and deep rendering with configurable depth, enabling isolated component testing or full tree rendering for comprehensive integration tests.

Familiar Enzyme-like API

Provides intuitive methods such as find(), simulate(), and setState(), making it easy for developers accustomed to Enzyme to write tests without a steep learning curve.

Jest Snapshot Integration

Includes a built-in snapshot serializer that seamlessly integrates with Jest for visual regression testing of Preact component outputs.

Lifecycle Method Testing

Directly supports testing lifecycle hooks like componentWillReceiveProps and componentWillUnmount through context.render() and other methods, as demonstrated in the examples.

Cons

Limited Selector Language

The CSS-like selectors are restricted and do not support nesting, which can hinder complex DOM queries and make test code more verbose.

Incomplete Enzyme Parity

As admitted in the README, it lacks many options available in Enzyme, such as advanced traversal methods, which may limit its utility for teams migrating from Enzyme.

Configuration Overhead

Requires manual setup for custom DOM implementations and has internal properties like SPY_PRIVATE_KEY that might inadvertently leak into component props, adding complexity.

Open Source Alternative To

Preact Render Spy is an open-source alternative to the following products:

e
enzyme

Enzyme is a JavaScript testing utility for React that makes it easier to test React components' output and behavior.

Frequently Asked Questions

Quick Stats

Stars178
Forks24
Contributors0
Open Issues15
Last commit3 years ago
CreatedSince 2017

Tags

#unit-testing#test-utilities#testing#test#vdom#preact#virtual-dom#jsx#component-testing#jest

Built With

P
Preact
J
JavaScript

Links & Resources

Website

Included in

Preact987
Auto-fetched 1 day ago

Related Projects

Preact IslandPreact Island

🏝 Create your own slice of paradise on any website.

Stars235
Forks11
Last commit1 year ago
Preact Testing LibraryPreact Testing Library

Simple and complete Preact DOM testing utilities that encourage good testing practices.

Stars157
Forks39
Last commit2 months ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub