Giter Site home page Giter Site logo

rut's Introduction

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

  • Type safe by design. Test with confidence.
  • First-class async support. Wait for async calls to finish before returning a rendered result. (Experimental)
  • Deep act() integration. Let Rut do the heavy lifting.
  • Update a component with new props, children, or a completely new element.
  • Unmount a component to verify cleanup and destructor based logic.
  • Dispatch DOM level events with a mocked synthetic event (and propagation coming soon!).
  • Wrap all renders with a defined wrapping component and or React.StrictMode.
  • Apply pre-built mocks for robust and accurate testing.
  • Utilize an array of pre-built matchers for easily querying, expecting, and asserting.

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

  • React 16.9+
  • Jest or another testing framework

Documentation

https://milesj.gitbook.io/rut

rut's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.