npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details


  • User packages



Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.


Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2023 – Pkg Stats / Ryan Hefner




Custom jest matchers to test the state of React Native




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 use 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.


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. Any issues raised with existing matchers or any newly proposed matchers must be viewed through compatibility with that library and its guiding principles first.


This module should be installed as one of your project's devDependencies:

Using yarn

yarn add --dev @testing-library/jest-native

Using npm

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.


Import @testing-library/jest-native/extend-expect once (for instance in your tests setup file) and you're good to go:

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:

import { toBeEmptyElement, toHaveTextContent } from '@testing-library/jest-native';

expect.extend({ toBeEmptyElement, toHaveTextContent });


jest-native has only been tested to work with React Native Testing Library. Keep in mind that these queries are intended only to work with elements corresponding to host components.



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)


const { getByTestId } = render(
    <Button disabled testID="button" title="submit" onPress={(e) => e} />
    <TextInput accessibilityState={{ disabled: true }} testID="input" value="text" />




Check whether or not an element is enabled from a user perspective.

Works similarly to expect().not.toBeDisabled().


const { getByTestId } = render(
    <Button testID="button" title="submit" onPress={(e) => e} />
    <TextInput testID="input" value="text" />




Check that the given element has no content.


const { getByTestId } = render(<View testID="empty" />);


Note This matcher has been previously named toBeEmpty(), but we changed that name in order to avoid conflict with Jest Extendend matcher with the same name.


toContainElement(element: ReactTestInstance | null);

Check if an element contains another element as a descendant. Again, will only work for native elements.


const { queryByTestId } = render(
  <View testID="grandparent">
    <View testID="parent">
      <View testID="child" />
    <Text testID="text-element" />

const grandparent = queryByTestId('grandparent');
const parent = queryByTestId('parent');
const child = queryByTestId('child');
const textElement = queryByTestId('text-element');




Check that the element is present in the element tree.

You can check that an already captured element has not been removed from the element tree.

Note This matcher requires React Native Testing Library v10.1 or later, as it includes the screen object.


    <View testID="child" />

const child = screen.getByTestId('child');

screen.update(<View />);


toHaveProp(prop: string, value?: any);

Check that the element has a given prop.

You can optionally check that the attribute has a specific expected value.


const { queryByTestId } = render(
    <Text allowFontScaling={false} testID="text">
    <Button disabled testID="button" title="ok" />

expect(queryByTestId('button')).not.toHaveProp('title', 'ok');


toHaveTextContent(text: string | RegExp, options?: { normalizeWhitespace: boolean });

Check if an element or its children have the supplied text.

This will perform a partial, case-sensitive match when a string match is provided. To perform a case-insensitive match, you can use a RegExp with the /i modifier.

To enforce matching the complete text content, pass a RegExp.


const { queryByTestId } = render(<Text testID="count-value">2</Text>);



toHaveStyle(style: object[] | object);

Check if an element has the supplied styles.

You can pass either an object of React Native style properties, or an array of objects with style properties. You cannot pass properties from a React Native stylesheet.


const styles = StyleSheet.create({ text: { fontSize: 16 } });

const { queryByText } = render(
      { color: 'black', fontWeight: '600', transform: [{ scale: 2 }, { rotate: '45deg' }] },
    Hello World

expect(getByText('Hello World')).toHaveStyle({ color: 'black' });
expect(getByText('Hello World')).toHaveStyle({ fontWeight: '600' });
expect(getByText('Hello World')).toHaveStyle({ fontSize: 16 });
expect(getByText('Hello World')).toHaveStyle([{ fontWeight: '600' }, { color: 'black' }]);
expect(getByText('Hello World')).toHaveStyle({ color: 'black', fontWeight: '600', fontSize: 16 });
expect(getByText('Hello World')).toHaveStyle({ transform: [{ scale: 2 }, { rotate: '45deg' }] });
expect(getByText('Hello World')).not.toHaveStyle({ color: 'white' });
expect(getByText('Hello World')).not.toHaveStyle({ transform: [{ scale: 2 }] });
expect(getByText('Hello World')).not.toHaveStyle({
  transform: [{ rotate: '45deg' }, { scale: 2 }],



Check that the given element is visible to the user.

An element is visible if all the following conditions are met:

  • it does not have its style property display set to none.
  • it does not have its style property opacity set to 0.
  • it is not a Modal component or it does not have the prop visible set to false.
  • it is not hidden from accessibility as checked by isHiddenFromAccessibility function from React Native Testing Library
  • its ancestor elements are also visible.


const { getByTestId } = render(<View testID="empty-view" />);

const { getByTestId } = render(<View testID="view-with-opacity" style={{ opacity: 0.2 }} />);

const { getByTestId } = render(<Modal testID="empty-modal" />);

const { getByTestId } = render(
      <View testID="view-within-modal" />

const { getByTestId } = render(<View testID="invisible-view" style={{ opacity: 0 }} />);

const { getByTestId } = render(<View testID="display-none-view" style={{ display: 'none' }} />);

const { getByTestId } = render(
  <View style={{ opacity: 0 }}>
      <View testID="view-within-invisible-view" />

const { getByTestId } = render(
  <View style={{ display: 'none' }}>
      <View testID="view-within-display-none-view" />

const { getByTestId } = render(
  <Modal visible={false}>
      <View testID="view-within-not-visible-modal" />

// Children elements of not visible modals are not rendered.
const { getByTestId } = render(<Modal testID="not-visible-modal" visible={false} />);

const { getByTestId } = render(<View testID="test" accessibilityElementsHidden />);

const { getByTestId } = render(
  <View testID="test" importantForAccessibility="no-hide-descendants" />,



toHaveAccessibilityState(state: {
  disabled?: boolean;
  selected?: boolean;
  checked?: boolean | 'mixed';
  busy?: boolean;
  expanded?: boolean;

Check that the element has given accessibility state entries.

This check is based on accessibilityState prop but also takes into account the default entries which have been found by experimenting with accessibility inspector and screen readers on both iOS and Android.

Some state entries behave as if explicit false value is the same as not having given state entry, so their default value is false:

  • disabled
  • selected
  • busy

The remaining state entries behave as if explicit false value is different than not having given state entry, so their default value is undefined:

  • checked
  • expanded

This matcher is compatible with *ByRole and *ByA11State queries from React Native Testing Library.


render(<View testID="view" accessibilityState={{ expanded: true, checked: true }} />);

// Single value match
expect(screen.getByTestId('view')).toHaveAccessibilityState({ expanded: true });
expect(screen.getByTestId('view')).toHaveAccessibilityState({ checked: true });

// Can match multiple entries
expect(screen.getByTestId('view')).toHaveAccessibilityState({ expanded: true, checked: true });

Default values handling:

render(<View testID="view" />);

// Matching states where default value is `false`
expect(screen.getByTestId('view')).toHaveAccessibilityState({ disabled: false });
expect(screen.getByTestId('view')).toHaveAccessibilityState({ selected: false });
expect(screen.getByTestId('view')).toHaveAccessibilityState({ busy: false });

// Matching states where default value is `undefined`
expect(screen.getByTestId('view')).not.toHaveAccessibilityState({ checked: false });
expect(screen.getByTestId('view')).not.toHaveAccessibilityState({ expanded: false });


toHaveAccessibilityValue(value: {
  min?: number;
  max?: number;
  now?: number;
  text?: string | RegExp;

Check that the element has given accessibilityValue prop entries.

This matcher is compatible with *ByRole and *ByA11Value queries from React Native Testing Library.


render(<View testID="view" accessibilityValue={{ min: 0, max: 100, now: 65 }} />);

const view = screen.getByTestId('view');

// Single value match
expect(view).toHaveAccessibilityValue({ now: 65 });
expect(view).toHaveAccessibilityValue({ max: 0 });

// Can match multiple entries
expect(view).toHaveAccessibilityValue({ min: 0, max: 100 });
expect(view).toHaveAccessibilityValue({ min: 0, max: 100, now: 65 });

// All specified entries need to match
expect(view).not.toHaveAccessibilityValue({ now: 45 });
expect(view).not.toHaveAccessibilityValue({ min: 20, max: 100, now: 65 });
render(<View testID="view" accessibilityValue={{ text: 'Almost full' }} />);

const view = screen.getByTestId('view');
expect(view).toHaveAccessibilityValue({ text: 'Almost full' });
expect(view).toHaveAccessibilityValue({ text: /full/ });


This library was made to be a companion for React Native Testing Library.

It was inspired by jest-dom, the companion library for DTL. We emulated as many of those helpers as we could while keeping in mind the guiding principles.

Other solutions

None known, you can add the first!


Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!