The `ra-test` package provides specialized utilities for efficiently testing applications built upon `react-admin`, a widely adopted frontend framework for developing administrative interfaces with React. As of early 2026, the current stable version of `react-admin` (and consequently `ra-test`, which is part of the same monorepo) is 5.14.6, characterized by a continuous release cadence with frequent minor updates and bug fixes. This library is specifically tailored to address the complexities of testing `react-admin` components, particularly custom views or logic that depend on the framework's intricate Redux store and React Router context. Unlike general React testing libraries, `ra-test` offers pre-configured wrappers like `TestContext` and helpers such as `renderWithRedux` that seamlessly provide the necessary `react-admin` environment, enabling developers to focus on the specific logic of their custom components rather than boilerplate setup. It differentiates itself by providing a robust, opinionated testing environment integrated deeply with `react-admin`'s architecture, making it easier to mock the `react-admin` state and dispatch actions for focused unit or integration tests within the ecosystem.
npm install ra-testVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `TestContext` to wrap a custom `react-admin` component, providing the necessary Redux and routing contexts for unit testing with `@testing-library/react`. It shows how to pass default props and simulate user interactions.
Ensure your `ra-test` package version matches the major version of your `react-admin` installation (e.g., `react-admin@5.x.x` requires `ra-test@5.x.x`). Upgrade both packages concurrently.
Focus your testing efforts on end-to-end scenarios for core application flows and on unit/integration testing your *custom* React components, mocking `react-admin`'s data providers or using `TestContext` for dependencies.
Always wrap your `react-admin` dependent components with `TestContext` or use the `renderWithRedux` helper. Remember to enable reducers if your component relies on Redux state changes (`<TestContext enableReducers />`).
If your component dispatches Redux actions or relies on Redux state updates, always pass the `enableReducers` prop to `TestContext`: `<TestContext enableReducers>{...}</TestContext>`.Ensure the component under test is wrapped within `<TestContext>` or rendered using `renderWithRedux`. For example: `render(<TestContext><MyComponent /></TestContext>)`
The component depending on `react-router` hooks or components must be rendered inside `TestContext`, which sets up the necessary `react-router` context. For example: `render(<TestContext><MyComponentThatUsesRouter /></TestContext>)`
If spying on `dispatch`, ensure you use the render prop pattern for `TestContext` to access the `store` object: `<TestContext>{({ store }) => { dispatchSpy = jest.spyOn(store, 'dispatch'); return <MyComponent />; }}</TestContext>`. Also, ensure `enableReducers` is set if state changes are expected.