Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/milesj/rut
⚛️ React testing made easy. Supports DOM and custom renderers.
https://github.com/milesj/rut
react rut testing unit-test
Last synced: 9 days ago
JSON representation
⚛️ React testing made easy. Supports DOM and custom renderers.
- Host: GitHub
- URL: https://github.com/milesj/rut
- Owner: milesj
- Archived: true
- Created: 2019-08-14T01:31:29.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-09-01T20:40:10.000Z (about 3 years ago)
- Last Synced: 2024-05-02T04:10:01.526Z (6 months ago)
- Topics: react, rut, testing, unit-test
- Language: TypeScript
- Homepage: https://ruttest.dev
- Size: 6.13 MB
- Stars: 16
- Watchers: 3
- Forks: 2
- Open Issues: 28
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
- awesome-react-components - rut - React testing made easy with `react-test-renderer`. Supports DOM and custom renderers. (Dev Tools / Test)
- awesome-react - rut - React testing made easy with `react-test-renderer`. Supports DOM and custom renderers. ![](https://img.shields.io/github/stars/milesj/rut.svg?style=social&label=Star) (Dev Tools / Test)
- awesome-react-components - rut - React testing made easy with `react-test-renderer`. Supports DOM and custom renderers. (Dev Tools / Test)
- awesome-react-components - rut - React testing made easy with `react-test-renderer`. Supports DOM and custom renderers. (Dev Tools / Test)
- fucking-awesome-react-components - rut - React testing made easy with `react-test-renderer`. Supports DOM and custom renderers. (Dev Tools / Test)
README
# Rut
[![Build Status](https://github.com/milesj/rut/workflows/Build/badge.svg)](https://github.com/milesj/rut/actions?query=branch%3Amaster)
[![npm version](https://badge.fury.io/js/rut.svg)](https://www.npmjs.com/package/rut)
[![npm deps](https://david-dm.org/milesj/rut.svg?path=packages/rut)](https://www.npmjs.com/package/rut)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](https://reactjs.org/docs/test-renderer.html) that simplifies the test writing
process, while doing all the hard work behind the scenes.```tsx
import { render } from 'rut-dom';
import Input, { InputProps } from '../src/Input';describe('', () => {
it('renders an input field', () => {
const { root, update } = render();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()`](https://reactjs.org/docs/testing-recipes.html#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](http://wiki.c2.com/?ArrangeActAssert) 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+ (Rut v1)
- React 17+ (Rut v2)
- Jest or another testing framework## Documentation
[https://ruttest.dev](https://ruttest.dev)