React DOM helpers for testing big
What is this?
This package aims to provide a set of helpers to make it easier to acceptance test your React applications.
mount helper will resolve after mounting a component in a
freshly inserted DOM node. Subsequent uses will clean up any previously
setupAppForTesting helper not only mounts the application
component, but will resolve with an instance of the component, and
provide an in-memory history object for React
Router to use during
visit helpers (
only work after using
setupAppForTesting and interface with the
history prop to navigate between routes.
cleanup helper is called at the start of every
setupAppForTesting call to clean up any previously mounted component
or application. It can be also used on it's own if you need to clean
up previously mounted components yourself.
setupAppForTesting accept a hash of
the second argument.
setupAppForTesting accepts a
props option which will
pass along any user-defined props to the application component.
For the most optimal experience when testing your application, any
required application logic that does not live in a component's
life-cycle hooks should be made reusable. Either by providing the
teardown options, or by moving the logic into
component life-cycle hooks.
In addition to this, it will probably make sense to make use of
setupAppForTesting inside of your own test helper where any other
necessary setup is taken care of. This also allows us to not have to
import our app and duplicate setup logic in every test file.
Even Better Testing
While these helpers allow you to repeatedly mount your application for testing, interacting with your application can also be troublesome.
provides an easy way to interact with the various parts of your app
via any browser, just like a user would interact with your app. In
fact, composable interactors are the perfect companion for testing
an app made with composable components.
Check out the
for more information about interactors and how they work.