1.0.0-alpha.14 • Published 3 years ago

@matejbransky/react-test-utils v1.0.0-alpha.14

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

@matejbransky/react-test-utils

Utilities for testing React components. It's based on @testing-library/react which provides light utility functions on top of react-dom and react-dom/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.

In addition to reexported utilities @matejbransky/react-test-utils enhances API and adds another useful functions.

Getting started

Requirements:

Installation:

yarn add @matejbransky/react-test-utils

Additional API to @testing-library/react

rerender(newProps: Record<string, unknown>): void

It's enhanced version of the original rerender() method from @testing-library/react. Enhanced version accepts only new components props so you don't need to repeat JSX signature with all original props + new props.

Example:

const { rerender } = render(<Counter name="Foobar" initialValue={4} />);

// re-render the same component with the original props and new props
rerender({ name: 'Bongo' });

Note: component's ref persists rerenders thanks to the React.cloneElement() method.