Testing Library

Testing Library

  • Docs
  • Recipes
  • Help
  • Blog

›Native Testing Library

Getting Started

  • Introduction
  • Guiding Principles

Frameworks

    DOM Testing Library

    • Introduction
    • Install
    • Example
    • Setup
    • Queries
    • Firing Events
    • Async Utilities
    • Helpers
    • Configuration
    • FAQ
    • Cheatsheet

    React Testing Library

    • Introduction
    • Example
    • Setup
    • API
    • FAQ
    • Cheatsheet

    Reason Testing Library

    • Introduction
    • Examples

    Native Testing Library

    • Introduction
    • Example
    • Setup
    • API

    Vue Testing Library

    • Introduction
    • Examples
    • Setup
    • API
    • Cheatsheet
    • FAQ

    Marko Testing Library

    • Introduction
    • Setup
    • API

    Angular Testing Library

    • Introduction
    • Examples
    • API

    Preact Testing Library

    • Introduction
    • Example
    • API
    • Learn

    Svelte Testing Library

    • Introduction
    • Setup
    • Example
    • API
  • Cypress Testing Library
  • Puppeteer Testing Library
  • Testcafe Testing Library
  • Nightwatch Testing Library

Ecosystem

  • user-event
  • jest-dom
  • bs-jest-dom
  • jest-native
  • react-select-event
  • eslint-plugin-testing-library
  • eslint-plugin-jest-dom
  • riot-testing-library
Edit

Introduction

Native Testing Library is a testing library for React Native inspired by DOM Testing Library. Because React Native does not run in a browser environment, the core queries are implemented independently, unlike other wrappers that use DOM Testing Library as the base. You'll find much more information about the library, including examples, on the project sites:

  • Docs
  • Docs repo
  • Project repo

Quickstart

npm install --save-dev @testing-library/react-native
  • Native Testing Library on GitHub

The problem

You want to write maintainable tests for your React Native application. You love testing library, and you want to be able to write maintainable tests for your React Native application also. 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. Accomplishing this is no small feat because of the differences between the two platforms. Although most framework implementations like React Testing Library are thin layers over DOM Testing Library, this library needed to have its own base implementation as well as a user-facing API. This library uses the react-test-renderer, whereas DOM Testing Library uses ReactDOM and JSDOM. The main philosophy is that you should find elements that are on the "screen" the way users would. This approach is meant to give you confidence that your app is working as a cohesive unit. Just like the DOM Testing Library, Native Testing Library's primary guiding principle is:

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

This library gives you the tools you need to find things in your application the way your users would. You can do things like find elements by text, input value, and accessibility labels -- the types of things your users can see. We also give you the ability to search for elements by testID, but you should consider it a last resort because users can't see a testID and it can introduce unpredictable behavior in your tests.

It will also encourage you to build more accessible apps. For example, your users can't see your icon touchable that doesn't have an accessibility label, so neither can your tests. We believe that writing good tests using this library will force you to give more consideration to whether what you're doing is an accessible experience for all of your users.

This library should, in theory, work with any any testing framework like Jest or Mocha, but we do recommend you use Jest with the react-native Jest preset. We have not tested it in any other environment, and likely won't be able to support usage with another library.

Last updated on 9/1/2019
← ExamplesExample →
  • Quickstart
  • The problem
  • This solution
Testing Library
Docs
Getting StartedExamplesAPIHelp
Community
BlogStack OverflowDiscord
More
StarGitHubEdit Docs on GitHubHosted by Netlify
Copyright © 2018-2020 Kent C. Dodds and contributors