# jest-native **Repository Path**: mirrors_testing-library/jest-native ## Basic Information - **Project Name**: jest-native - **Description**: ๐Ÿฆ… Custom jest matchers to test the state of React Native - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-08-25 - **Last Updated**: 2026-03-01 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README > [!CAUTION] > **This package is deprecated and is no longer actively maintained.** > > We encourage you to migrate to React Native Testing Library, v12.4 or later, which includes modern [built-in Jest matchers](https://callstack.github.io/react-native-testing-library/docs/api/jest-matchers) based on the matchers for this repository. > > The migration process should be relatively straightforward, we have a [migration guide](https://callstack.github.io/react-native-testing-library/docs/migration/jest-matchers) available.

jest-native

eagle

Custom jest matchers to test the state of React Native.


[![version](https://img.shields.io/npm/v/@testing-library/jest-native.svg?style=flat-square)](https://www.npmjs.com/package/@testing-library/jest-native) [![Code Coverage](https://img.shields.io/codecov/c/github/testing-library/jest-native.svg?style=flat-square)](https://codecov.io/github/testing-library/jest-native) ![Build](https://github.com/testing-library/jest-native/actions/workflows/validate.yml/badge.svg) [![downloads](https://img.shields.io/npm/dm/@testing-library/jest-native.svg?style=flat-square)](http://www.npmtrends.com/@testing-library/jest-native) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com) [![Discord](https://img.shields.io/discord/723559267868737556.svg?color=7389D8&labelColor=6A7EC2&logo=discord&logoColor=ffffff&style=flat-square)](https://discord.gg/testing-library) [![Star on GitHub](https://img.shields.io/github/stars/testing-library/jest-native.svg?style=social)](https://github.com/testing-library/jest-native/stargazers) ## Table of Contents - [The problem](#the-problem) - [This solution](#this-solution) - [Compatibility](#compatibility) - [Installation](#installation) - [Usage](#usage) - [Extending Jest matchers](#extending-jest-matchers) - [TypeScript support](#typescript-support) - [Matchers](#matchers) - [`toBeDisabled`](#tobedisabled) - [`toBeEnabled`](#tobeenabled) - [`toBeEmptyElement`](#tobeemptyelement) - [`toContainElement`](#tocontainelement) - [`toBeOnTheScreen`](#tobeonthescreen) - [`toHaveProp`](#tohaveprop) - [`toHaveTextContent`](#tohavetextcontent) - [`toHaveStyle`](#tohavestyle) - [`toBeVisible`](#tobevisible) - [`toHaveAccessibilityState`](#tohaveaccessibilitystate) - [`toHaveAccessibilityValue`](#tohaveaccessibilityvalue) - [Inspiration](#inspiration) - [Other solutions](#other-solutions) - [Contributors](#contributors) ## The problem You want to use [jest](https://facebook.github.io/jest/) to write tests that assert various things about the state of a React Native app. As part of that goal, you want to avoid all the repetitive patterns that arise in doing so like checking for a native element's props, its text content, its styles, and more. ## This solution The `jest-native` library provides a set of custom jest matchers that you can use to extend jest. These will make your tests more declarative, clear to read and to maintain. ## Compatibility These matchers should, for the most part, be agnostic enough to work with any React Native testing utilities, but they are primarily intended to be used with [React Native Testing Library](https://github.com/callstack/react-native-testing-library). Any issues raised with existing matchers or any newly proposed matchers must be viewed through compatibility with that library and its guiding principles first. ## Installation This module should be installed as one of your project's `devDependencies`: #### Using `yarn` ```sh yarn add --dev @testing-library/jest-native ``` #### Using `npm` ```sh npm install --save-dev @testing-library/jest-native ``` You will need `react-test-renderer`, `react`, and `react-native` installed in order to use this package. ## Usage ### Extending Jest matchers Import `@testing-library/jest-native/extend-expect` once (for instance in your [tests setup file](https://jestjs.io/docs/configuration#setupfilesafterenv-array)) and you're good to go: ```javascript import '@testing-library/jest-native/extend-expect'; ``` Alternatively, you can selectively import only the matchers you intend to use, and extend jest's `expect` yourself: ```javascript import { toBeEmptyElement, toHaveTextContent } from '@testing-library/jest-native'; expect.extend({ toBeEmptyElement, toHaveTextContent }); ``` ### TypeScript support In order to setup proper TypeScript type checking use either one of the following approches. #### 1. Use TypeScript Jest setup file. Use `jest-setup.ts` file (instead of `jest-setup.js` file) which is added to Jest config's `setupFilesAfterEnv` option. The Jest setup file should contain following line: ```typescript import '@testing-library/jest-native/extend-expect'; ``` This should enable TypeScript checkign for both `tsc` and VS Code intellisense. #### 2. Use `declarations.d.ts` file Alternatively, create `declarations.d.ts` file at the root level of your project, if it does not exist already. Add following line at the top of your `declarations.d.ts`: ``` /// ``` This should enable TypeScript checkign for both `tsc` and VS Code intellisense. ## Matchers `jest-native` has only been tested to work with [React Native Testing Library](https://github.com/callstack/react-native-testing-library). Keep in mind that these queries are intended only to work with elements corresponding to [host components](https://reactnative.dev/architecture/glossary#react-host-components-or-host-components). ### `toBeDisabled` ```javascript toBeDisabled(); ``` Check whether or not an element is disabled from a user perspective. This matcher will check if the element or its parent has any of the following props : - `disabled` - `accessibilityState={{ disabled: true }}` - `editable={false}` (for `TextInput` only) #### Examples ```javascript const { getByTestId } = render(