Reakit Test Utilities

0.15.2 · renamed · verified Wed Apr 22

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

Warnings

Install

Imports

Quickstart

Demonstrates rendering a simple React component and interacting with it using `fireEvent` and `act` to test state changes, typical for UI component testing. This example assumes a Jest and `@testing-library/jest-dom` setup.

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();
  });
});

view raw JSON →