Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/testing-library/native-testing-library
π³ Simple and complete React Native testing utilities that encourage good testing practices.
https://github.com/testing-library/native-testing-library
javascript jest react-native reactjs testing
Last synced: 3 months ago
JSON representation
π³ Simple and complete React Native testing utilities that encourage good testing practices.
- Host: GitHub
- URL: https://github.com/testing-library/native-testing-library
- Owner: testing-library
- License: mit
- Archived: true
- Created: 2019-04-01T12:50:40.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-07-30T14:35:27.000Z (over 4 years ago)
- Last Synced: 2024-04-14T01:49:26.077Z (7 months ago)
- Topics: javascript, jest, react-native, reactjs, testing
- Language: JavaScript
- Homepage: https://native-testing-library.com
- Size: 481 KB
- Stars: 515
- Watchers: 19
- Forks: 42
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
- awesome-list - native-testing-library - library | 524 | (JavaScript)
README
# β οΈ Deprecation notice β οΈ
This repository has been deprecated in favor of https://github.com/callstack/react-native-testing-library and the `@testing-library/react-native` npm package will from now on (since v7.0) will be sourced from there. Please consult the [migration guide](https://callstack.github.io/react-native-testing-library/docs/migration-v7/#guide-for-testing-libraryreact-native-users).
Native Testing Library
Simple and complete React Native testing utilities that encourage good testing practices.
[**Read The Docs**](https://native-testing-library.com/docs/intro) |
[Edit the docs](https://github.com/testing-library/native-testing-library-docs)
[![Build Status](https://travis-ci.org/testing-library/native-testing-library.svg?branch=master)](https://travis-ci.org/testing-library/native-testing-library)
[![Code Coverage](https://img.shields.io/codecov/c/github/testing-library/native-testing-library.svg?style=flat-square)](https://codecov.io/github/testing-library/native-testing-library)
[![version](https://img.shields.io/npm/v/@testing-library/react-native.svg?style=flat-square)](https://www.npmjs.com/package/@testing-library/react-native)
[![downloads](https://img.shields.io/npm/dm/@testing-library/react-native.svg?style=flat-square)](http://www.npmtrends.com/@testing-library/react-native)
[![MIT License](https://img.shields.io/npm/l/@testing-library/react-native.svg?style=flat-square)](https://github.com/testing-library/native-testing-library/blob/master/LICENSE)[![All Contributors](https://img.shields.io/badge/all_contributors-16-orange.svg?style=flat-square)](#contributors)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
[![Code of Conduct](https://img.shields.io/badge/code%20of-conduct-ff69b4.svg?style=flat-square)](https://github.com/testing-library/native-testing-library/blob/master/CODE_OF_CONDUCT.md)
[![Discord](https://img.shields.io/discord/723559267868737556.svg?color=7389D8&labelColor=6A7EC2&logo=discord&logoColor=ffffff&style=flat-square)](https://discord.gg/c6JN9fM)[![Watch on GitHub](https://img.shields.io/github/watchers/testing-library/native-testing-library.svg?style=social)](https://github.com/testing-library/native-testing-library/watchers)
[![Star on GitHub](https://img.shields.io/github/stars/testing-library/native-testing-library.svg?style=social)](https://github.com/testing-library/native-testing-library/stargazers)## Table of Contents
- [The problem](#the-problem)
- [This solution](#this-solution)
- [Example](#example)
- [Installation](#installation)
- [Hooks](#hooks)
- [Other Solutions](#other-solutions)
- [Guiding Principles](#guiding-principles)
- [Inspiration](#inspiration)
- [Contributors](#contributors)
- [Docs](#docs)## The problem
You want to write maintainable tests for your React Native application. You love Kent Dodds' testing
library, and you want to be able to write maintainable tests for your React Native application. You
don't want to use a library that renders components to a fake DOM, and you've had a hard time
finding what you need to write tests using that philosophy in React Native.## This solution
`native-testing-library` is an implementation of the well-known testing-library API that works for
React Native. The primary goal is to mimic the testing library API as closely as possible while
still accounting for the differences in the platforms.## Example
```javascript
import React from 'react';
import { Button, Text, TextInput, View } from 'react-native';
import { fireEvent, render, wait } from '@testing-library/react-native';function Example() {
const [name, setUser] = React.useState('');
const [show, setShow] = React.useState(false);return (
{
// let's pretend this is making a server request, so it's async
// (you'd want to mock this imaginary request in your unit tests)...
setTimeout(() => {
setShow(!show);
}, Math.floor(Math.random() * 200));
}}
/>
{show && {name}}
);
}test('examples of some things', async () => {
const { getByTestId, getByText, queryByTestId, baseElement } = render();
const famousWomanInHistory = 'Ada Lovelace';const input = getByTestId('input');
fireEvent.changeText(input, famousWomanInHistory);const button = getByText('Print Username');
fireEvent.press(button);await wait(() => expect(queryByTestId('printed-username')).toBeTruthy());
expect(getByTestId('printed-username').props.children).toBe(famousWomanInHistory);
expect(baseElement).toMatchSnapshot();
});
```## Installation
This module should be installed in your project's `devDependencies`:
```
npm install --save-dev @testing-library/react-native
```You will need `react` and `react-native` installed as _dependencies_ in order to run this project.
## Hooks
If you are interested in testing a custom hook, check out
[react-hooks-testing-library](https://github.com/mpeyper/react-hooks-testing-library).## Other Solutions
- [`react-native-testing-library`](https://github.com/callstack/react-native-testing-library)
- [`enzyme`](https://airbnb.io/enzyme/docs/guides/react-native.html)## Guiding principles
> [The more your tests resemble the way your software is used, the more confidence they can give you.](https://twitter.com/kentcdodds/status/977018512689455106)
We try to only expose methods and utilities that encourage you to write tests that closely resemble
how your apps are used.Utilities are included in this project based on the following guiding principles:
1. If it relates to rendering components, it deals with native views rather than component
instances, nor should it encourage dealing with component instances.
2. It should be generally useful for testing the application components in the way the user would
use it. We are making some trade-offs here because we're using a computer and often a simulated
environment, but in general, utilities should encourage tests that use the components the way
they're intended to be used.
3. Utility implementations and APIs should be simple and flexible.In summary, we believe in the principles of `testing-library`, and adhere to them as closely as
possible. At the end of the day, what we want is for this library to be pretty light-weight, simple,
and understandable.## Inspiration
Huge thanks to Kent C. Dodds for evangelizing this approach to testing. We could have never come up
with this library without him π. Check out his awesome work and learn more about testing with
confidence at [testingjavascript.com](https://testingjavascript.com/) (you won't regret purchasing
it), and of course, use this library's big brother, `react-testing-library` for your DOM
applications as well!The hook testing ability of this library is the same implementation as
[react-hooks-testing-library](https://github.com/mpeyper/react-hooks-testing-library). The only
reason it was included in this package is because we need you to import render from us, not the
`dom-testing-library`, and that's an important blocker. Some day, maybe we'll try to allow use of
that library with this one somehow.## Contributors
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
Brandon Carroll
π» π π β οΈ
Tommy Graves
π€ π§ π
Kent C. Dodds
π€
Piotr Szlachciak
π»
mcgloneleviROOT
π π»
Kevin Sullivan
π
Ely Alvarado
π»
Lewis Barnes
π» π¬
James DiGioia
π»
mana
π»
Mateusz MΔdrek
π»
Ismail Ghallou
π
jeffreyffs
π»
Sophie Au
π»
andy
π» π
Aiham
π»
Sibelius Seraphini
π»
Alex Egan
π»
Dave Olsen
π» β οΈ π
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors)
specification. Contributions of any kind welcome!## Docs
[**Read The Docs**](https://native-testing-library.com) |
[Edit the docs](https://github.com/testing-library/native-testing-library-docs)