Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/moveaxlab/react-native-invariants
- Owner: moveaxlab
- License: mit
- Created: 2019-06-08T11:45:32.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-03T23:40:58.000Z (almost 2 years ago)
- Last Synced: 2024-04-20T04:22:23.152Z (7 months ago)
- Topics: react-native, unit-testing
- Language: TypeScript
- Size: 1.96 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 19
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
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