rc-test is a focused testing utility library designed for React components, primarily built as a wrapper and pre-configurator for Jest. It streamlines the setup of the testing environment for React projects by providing a customized Jest runner and re-exporting common Jest functions along with specific React component testing helpers. The current stable version is 7.1.3. Releases are typically driven by dependency updates, Jest compatibility fixes, and new utility additions, with a fairly active development cadence as indicated by recent minor version bumps. Its key differentiator lies in simplifying React testing boilerplate, addressing common environment issues like `jsdom` configurations and `ResizeObserver` mocks, and ensuring compatibility with various Jest versions, rather than introducing a new testing paradigm.
npm install rc-testVerified import paths — ran on the pinned version, not inferred.
Demonstrates defining a simple React component test using `rc-test`'s `createTest` utility and running it via the CLI.
Migrate your existing Enzyme tests to use React Testing Library (e.g., `@testing-library/react`). Update test files to use `render`, `screen`, `fireEvent`, etc., instead of Enzyme's `mount` or `shallow`.
Ensure your Jest configuration and dependencies are aligned with Jest 28 best practices. Refer to the Jest migration guide for any specific breaking changes relevant to your test suite.
Ensure `rc-test` is correctly invoked to set up the testing environment. If you encounter `ResizeObserver` errors despite using `rc-test` (e.g., in a non-standard setup), you might need to manually add a global mock for `ResizeObserver` to your Jest setup files.
Run tests using `rc-test` via a script in `package.json` (e.g., `"test": "rc-test"`) rather than directly invoking `jest`. If importing utilities, ensure correct import paths as shown in the `imports` section.
Add a global mock for `window.matchMedia` in your Jest setup file. `rc-test` should handle common cases, but specific configurations might require manual intervention. Example: `Object.defineProperty(window, 'matchMedia', { writable: true, value: jest.fn().mockImplementation(query => ({ matches: false, media: query, onchange: null, addListener: jest.fn(), removeListener: jest.fn(), addEventListener: jest.fn(), removeEventListener: jest.fn(), dispatchEvent: jest.fn() })) });`Change the import statement to `import createTest from 'rc-test/lib/createTest';`.
Move `jest.mock()` calls to the top level of the test file, outside of any `describe` or `test` blocks. If conditional mocking is needed, consider `jest.doMock()` within specific contexts.