All Projects β†’ testing-library β†’ Native Testing Library

testing-library / Native Testing Library

Licence: mit
🐳 Simple and complete React Native testing utilities that encourage good testing practices.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Native Testing Library

Enzyme
JavaScript Testing utilities for React
Stars: ✭ 19,781 (+3660.65%)
Mutual labels:  jest
Gatsby Starter Ecommerce
Gatsby starter for creating an eCommerce site using the Moltin eCommerce Api
Stars: ✭ 448 (-14.83%)
Mutual labels:  jest
Snowflake
❄️ A React-Native Android iOS Starter App/ BoilerPlate / Example with Redux, RN Router, & Jest with the Snowflake Hapi Server running locally or on RedHat OpenShift for the backend, or a Parse Server running locally or remotely on Heroku
Stars: ✭ 4,576 (+769.96%)
Mutual labels:  jest
Jest Runner Eslint
An ESLint runner for Jest
Stars: ✭ 401 (-23.76%)
Mutual labels:  jest
Youtube React
A Youtube clone built in React, Redux, Redux-saga
Stars: ✭ 421 (-19.96%)
Mutual labels:  jest
Ts Monorepo
Template for setting up a TypeScript monorepo
Stars: ✭ 459 (-12.74%)
Mutual labels:  jest
Typescript Library Starter
Starter kit with zero-config for building a library in TypeScript, featuring RollupJS, Jest, Prettier, TSLint, Semantic Release, and more!
Stars: ✭ 3,943 (+649.62%)
Mutual labels:  jest
Jest Clean Console Reporter
A Jest Reporter to group, hide and prettify spammy console warnings
Stars: ✭ 520 (-1.14%)
Mutual labels:  jest
Entria Fullstack
Monorepo Playground with GraphQL, React, React Native, Relay Modern, TypeScript and Jest
Stars: ✭ 434 (-17.49%)
Mutual labels:  jest
Snapshot Diff
Diffing snapshot utility for Jest
Stars: ✭ 490 (-6.84%)
Mutual labels:  jest
Jest Cheat Sheet
Jest cheat sheet
Stars: ✭ 4,309 (+719.2%)
Mutual labels:  jest
Expect Jsx
βœ… toEqualJSX for expect assertion library
Stars: ✭ 411 (-21.86%)
Mutual labels:  jest
Laravel Vue Boilerplate
🐘 A Laravel 6 SPA boilerplate with a users CRUD using Vue.js 2.6, GraphQL, Bootstrap 4, TypeScript, Sass, and Pug.
Stars: ✭ 472 (-10.27%)
Mutual labels:  jest
Gatsby Starter
Gatsby 2.0 starter with typescript and many cools dev tools
Stars: ✭ 385 (-26.81%)
Mutual labels:  jest
React Typescript Web Extension Starter
πŸ–₯ A Web Extension starter kit built with React, TypeScript, SCSS, Storybook, Jest, EsLint, Prettier, Webpack and Bootstrap. Supports Google Chrome + Mozilla Firefox + Brave Browser πŸ”₯
Stars: ✭ 510 (-3.04%)
Mutual labels:  jest
Js Stack From Scratch
πŸ› οΈβš‘ Step-by-step tutorial to build a modern JavaScript stack.
Stars: ✭ 18,814 (+3476.81%)
Mutual labels:  jest
Opensource
Delivering delightful digital solutions. Open Source packages with combined ~85M/month downloads, semantically versioned following @conventional-commits. Fully powered by Jest, @Babel TypeScript, @Airbnb @ESLint + @Prettier, @YarnPKG + @Lerna independent versioning, GH @Actions & automated dep updates with @RenovateBot.
Stars: ✭ 459 (-12.74%)
Mutual labels:  jest
React Screenshot Test
A dead simple library to screenshot test React components
Stars: ✭ 519 (-1.33%)
Mutual labels:  jest
Pepperoni App Kit
Pepperoni - React Native App Starter Kit for Android and iOS
Stars: ✭ 4,657 (+785.36%)
Mutual labels:  jest
Ts Jest
A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.
Stars: ✭ 5,380 (+922.81%)
Mutual labels:  jest

⚠️ 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.

Native Testing Library

whale

Simple and complete React Native testing utilities that encourage good testing practices.

Read The Docs | Edit the docs


Build Status Code Coverage version downloads MIT License

All Contributors PRs Welcome Code of Conduct Discord

Watch on GitHub Star on GitHub

Table of Contents

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

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 (
    <View>
      <TextInput value={name} onChangeText={setUser} testID="input" />
      <Button
        title="Print Username"
        onPress={() => {
          // 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 && <Text testID="printed-username">{name}</Text>}
    </View>
  );
}

test('examples of some things', async () => {
  const { getByTestId, getByText, queryByTestId, baseElement } = render(<Example />);
  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.

Other Solutions

Guiding principles

The more your tests resemble the way your software is used, the more confidence they can give you.

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 (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. 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):


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 specification. Contributions of any kind welcome!

Docs

Read The Docs | Edit the docs

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].