Reakit Test Utilities
The `reakit-test-utils` package provides a set of utilities designed to facilitate testing of components built with the Reakit library, primarily using `@testing-library/react` and `@testing-library/react-hooks`. While the current version is 0.15.2, active development for the Reakit ecosystem has transitioned to the Ariakit project, with `reakit-test-utils` being effectively superseded by `@ariakit/test`. This package integrates with standard testing-library APIs to enable robust, accessibility-focused testing of UI components, emphasizing user interactions over internal implementation details. Developers should note that this specific package is no longer actively maintained under the `reakit-test-utils` name, and new projects or migrations should consider using `@ariakit/test` for ongoing support and features. Its original release cadence was irregular, marked by an 'experimental' status, leading to potential breaking changes even in minor versions before the migration to Ariakit.
Common errors
-
Error: `act` is not supported in the current environment.
cause Using `act` outside of a React testing environment or with an outdated test setup that doesn't correctly wrap state updates, or if React's `act` is not properly shimmed/imported.fixEnsure `act` is imported from `reakit-test-utils` (or `@testing-library/react` if directly using it) and that your test runner (e.g., Jest) is configured correctly. For asynchronous operations, ensure you `await act(async () => { ... })`. -
TypeError: (0, _reakit_test_utils__WEBPACK_IMPORTED_MODULE_2__.render) is not a function
cause Incorrect import of named exports or attempting to use CommonJS `require` syntax when the environment expects ESM, or vice-versa. Can also occur if the package is not installed or if bundler configuration is incorrect.fixVerify that `reakit-test-utils` is installed and ensure you are using named imports (e.g., `import { render } from 'reakit-test-utils'`). If you are migrating from Reakit to Ariakit, update imports to `@ariakit/test`.
Warnings
- breaking The `reakit-test-utils` package has been superseded by `@ariakit/test` due to the rebranding of Reakit to Ariakit. It is no longer actively maintained under this name, and developers should migrate to `@ariakit/test` for ongoing support, features, and bug fixes.
- gotcha This package was explicitly marked as 'experimental' in its README, indicating that it was subject to breaking changes even in minor versions. Relying on its specific API or behavior for long-term projects could lead to unexpected issues.
- gotcha Peer dependency ranges for `react` and `react-dom` are restricted to `^16.8.0 || ^17.0.0`. Using this package with React 18 or newer may lead to peer dependency warnings or runtime issues, as it hasn't been officially updated to support them.
Install
-
npm install reakit-test-utils -
yarn add reakit-test-utils -
pnpm add reakit-test-utils
Imports
- render
const { render } = require('reakit-test-utils')import { render } from 'reakit-test-utils' - fireEvent
import fireEvent from 'reakit-test-utils'
import { fireEvent } from 'reakit-test-utils' - act
import { act } from '@testing-library/react'import { act } from 'reakit-test-utils'
Quickstart
import * as React from 'react';
import { render, fireEvent, act } from 'reakit-test-utils';
// You would also need @testing-library/jest-dom for toBeInTheDocument
// import '@testing-library/jest-dom';
const Counter = () => {
const [count, setCount] = React.useState(0);
return (
<div>
<button onClick={() => setCount(c => c + 1)}>Increment</button>
<p>Count: {count}</p>
</div>
);
};
describe('Counter Component', () => {
it('should increment the count when button is clicked', async () => {
const { getByText } = render(<Counter />);
const incrementButton = getByText('Increment');
const countDisplay = getByText('Count: 0');
expect(countDisplay).toBeInTheDocument();
await act(async () => {
fireEvent.click(incrementButton);
});
expect(getByText('Count: 1')).toBeInTheDocument();
});
});