Skip to main content

Introduction

The problem

You want to write maintainable tests for Web-interoperable runtimes. As a part of this goal, you want your tests to avoid including implementation details of your components and rather focus on making your tests give you the confidence for which they are intended. As part of this, you want your testbase to be maintainable in the long run so refactors of your components (changes to implementation but not functionality) don't break your tests and slow you and your team down.

This solution

The Web Testing Library is a very light-weight solution for testing code that runs on Web-interoperable runtimes (a browser, Node.js, Deno etc.) or React Native. The Web Testing Library's primary guiding principle is:

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

We try to only expose methods and utilities that encourage you to write tests that closely resemble how your code is used on the Web Platform or React Native.

Utilities are included in this project based on the following guiding principles:

  1. They should be usable on the minimum common web platform API
  2. It should be generally useful for testing the application in the way the user would use it. We are making some trade-offs here because we're using a computer and often a simulated environment, but in general, utilities should encourage tests that use the application the way they're intended to be used.
  3. Utility implementations and APIs should be simple and flexible.

What this library is not:

  1. A test runner or framework
  2. Specific to a testing framework (though we do have better defaults for Jest like support for fake timers).