component-test-setup is a utility library designed to standardize boilerplate code for setting up React component tests. It serves as a thin wrapper over popular testing libraries like React Testing Library (RTL) and Enzyme, abstracting away common patterns for initializing components with default props. The current stable version is 0.3.3, indicating it's in pre-1.0 development, but actively maintained by Codecademy. Its primary differentiator is providing a consistent API (`setupRtl`, `setupEnzyme`) that returns a render function (`renderView`, `renderWrapper`) and an `update` method, reducing redundancy across test files. It simplifies managing initial and updated props for both Enzyme and RTL-based tests, allowing developers to focus on component logic rather than test setup specifics.
npm install component-test-setupVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `setupRtl` to create a `renderView` function for a simple React component, showing initial rendering with default and overridden props, and then how to use the `update` method to simulate prop changes for testing component lifecycle or hook effects.
After calling the `update` method, do not rely on the `props` object for the latest values. Instead, retrieve the updated state or content directly from the `view` (RTL) or `wrapper` (Enzyme) via queries or methods.
Ensure you install the necessary peer dependencies (e.g., `npm install --save-dev @testing-library/react` or `npm install --save-dev enzyme enzyme-adapter-react-18`) based on your chosen testing approach.
Always provide a complete set of desired props to `update` if you need to ensure the exact prop state, or carefully manage partial updates knowing they will be shallowly merged.