Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/moveaxlab/react-native-invariants

Check React Native invariants with react-test-renderer.
https://github.com/moveaxlab/react-native-invariants

react-native unit-testing

Last synced: about 22 hours ago
JSON representation

Check React Native invariants with react-test-renderer.

Awesome Lists containing this project

README

        

# React Native Invariants

[![Travis (.com)](https://img.shields.io/travis/com/moveaxlab/react-native-invariants.svg)](https://travis-ci.com/moveaxlab/react-native-invariants)
[![Coveralls github](https://img.shields.io/coveralls/github/moveaxlab/react-native-invariants.svg)](https://coveralls.io/github/moveaxlab/react-native-invariants)
[![npm](https://img.shields.io/npm/v/react-native-invariants.svg)](https://www.npmjs.com/package/react-native-invariants)

This package checks React Native invariants not covered by `react-test-renderer` and friends.

## Motivation

Libraries like `react-test-renderer` and `react-native-testing-library` overlook React Native invariant violations (obviously).
We want to detect this type of errors in unit tests, while waiting for [Enzyme][enzyme-thread] to hopefully catch up.

```jsx


Loading in progress...

```

The most common mistakes (for us non-native developers) are raw text not inside Text components, and Views inside Text components.
This library detects both.

## Installation

```bash
yarn add --dev react-native-invariants react-test-renderer
```

## Usage

```jsx
import React from 'react';
import renderer from 'react-test-renderer';
import { checkInvariants } from 'react-native-invariants';
import { MyComponent } from '../somewhere';

it('Tests a React Native component', () => {
const tree = renderer.create().toJSON();
checkInvariants(tree);
});
```

Or redefine a render method to always check invariants.

[enzyme-thread]: https://github.com/airbnb/enzyme/issues/1436