Home

Awesome

Rut

Build Status npm version npm deps

Rut is a DOM-less React testing library that aims to be lightweight, encourage great testing practices, and reduce flakiness and code smells. It is a wrapper and abstraction around react-test-renderer that simplifies the test writing process, while doing all the hard work behind the scenes.

import { render } from 'rut-dom';
import Input, { InputProps } from '../src/Input';

describe('<Input />', () => {
  it('renders an input field', () => {
    const { root, update } = render<InputProps>(<Input name="rut" value="foo" />);

    expect(root).toHaveProp('name', 'rut');
    expect(root).toHaveValue('foo');
    expect(root).not.toBeDisabled();

    update({ disabled: true });

    expect(root).toBeDisabled();
  });
});

The rut package provides core functionality for adapters to expand upon. For example, a DOM adapter for react-dom, a mobile native adapter for react-native, or even a custom adapter unique to your application.

Features

Best Practices

Encourages the Arrange-Act-Assert testing pattern.

Arrange: Renders the entire component tree (instead of shallow) for a more accurate representation of your component. Requires fetches, events, contexts, and more, to be properly mocked or setup before hand.

Act: With no direct access to state or internals, it forces you to interact with your tree in the same manner your user would. Dispatch events to toggle states or execute handlers, like a form submission.

Assert: Test your expectations using pre-built matchers for common testing scenarios and patterns while avoiding implementation details.

Requirements

Documentation

https://ruttest.dev