Skip to main content

Intro

Preact Testing Library on GitHub

npm install --save-dev @testing-library/preact

This library is built on top of DOM Testing Library which is where most of the logic behind the queries is.

The Problem

You want to write tests for your Preact components so that they avoid including implementation details, and are maintainable in the long run.

This Solution

The Preact Testing Library is a very lightweight solution for testing Preact components. It provides light utility functions on top of preact/test-utils, in a way that encourages better testing practices. Its primary guiding principle is:

The more your tests resemble the way your software is used, the more confidence they can give you.

See the Dom introduction and React introduction for a more in-depth explanation.

What this library is not:

  1. A test runner or framework.
  2. Specific to a testing framework.

We recommend Jest as our preference. You can checkout Using Without Jest if you're looking to use another framework.