Questions tagged [react-native-testing-library]

The react-native-testing-library is a lightweight solution for testing your React Native components. It provides light utility functions on top of react-test-renderer letting you always be up to date with latest React features and write any component tests you like.

The react-native-testing-library is a lightweight solution for testing your React Native components. It provides light utility functions on top of react-test-renderer letting you always be up to date with latest React features and write any component tests you like.

This library is a replacement for Enzyme. It is tested to work with Jest, but it should work with other test runners as well.

https://github.com/callstack/react-native-testing-library

177 questions
5
votes
2 answers

How to assert that a button is disabled in React Native Testing Library?

How can I assert that a button is disabled in React Native Testing Library? I would imagine something like: expect(getByRole('button')).toBeDisabled() but RNTL doesn't provide toBeDisabled assertion.
Petr K.
  • 530
  • 6
  • 12
5
votes
0 answers

What is the best practice for unit testing my functional component with hooks in React Native?

I've written a simple wrapper component around ScrollView that enables/disables scrolling based on the available height it's given: import React, {useCallback, useEffect, useRef, useState} from 'react'; import {Keyboard, ScrollView} from…
5
votes
3 answers

How to properly test React Native Modals using Jest and Native Testing Library

I'm having a bit of a hard time understanding how to test my modal component. I'm using the react-native-modals package and @testing-library/react-native with Jest. My component is a modal that pops up when a GraphQL error is passed to it.…
Śāntanu
  • 203
  • 3
  • 9
4
votes
2 answers

IDE does not recognize Jest and its functions

I have a basic react-native/expo template app. I have added jest-expo and react-test-renderer in the dev dependencies, and also have updated package.json like documented in the expo docs for testing. { "main": "node_modules/expo/AppEntry.js", …
4
votes
0 answers

How to mock firebase firestore using jest with @react-native-firebase/firestore

I'm new to testing and I'm trying to fake a document update call using Jest. To do so I'm using react-native-testing-library and react-native-firebase. Below is my test suite. I have one input, and when I'm changing its value the document should be…
4
votes
1 answer

Styled-components theme with react-native testing-library

I've been stuck for a while trying to figure out exactly what I'm doing wrong here and I feel like I've tried every solution that I've found and it doesn't work. To describe what's happening, I made the most simple component I could to show what was…
4
votes
0 answers

How to select an element by accessibility role and label in React Native Testing Library

I have multiple buttons on my screen with different accessibilityLabel. Querying with getByRole ignores the second argument specifying…
Petr K.
  • 530
  • 6
  • 12
4
votes
0 answers

expect(jest.fn()).toHaveBeenCalledWith(...expected) in react-native and expo

I'm trying to write the unit test for the Controller which is written in react-native and expo Following is the login method for which Unit test is failing login.tsx import React, { useState } from 'react'; import { StyleSheet, SafeAreaView, Text,…
4
votes
1 answer

Issue Testing the DateTimePickerModal with Jest & React Native Testing Library

I am trying to write unit tests for the React Native Modal DateTime Picker using Jest and the React Native Testing Library. I've passed in 3 (what I believe are) standard RN props: accessible: true, accessibilityLabel: testLabel, testID:…
3
votes
1 answer

React Native Testing Library: scroll FlatList to bottom

I have a react-native FlatList component with onEndReached event used to load more items. I am testing the component with react-native-testing-library. The test is as follows: Component mounted. Requests 10 items to mockedBackend. Expect FlatList…
Elolawyn
  • 131
  • 1
  • 11
3
votes
1 answer

Invalid return value in simple jest test

I am testing a view for Home component for React Native 0.68.2/jest 29.0. The simple test case is copied from jest doc: import React from 'react'; import { NavigationContainer } from '@react-navigation/native'; import { render, cleanup, screen,…
user938363
  • 9,990
  • 38
  • 137
  • 303
3
votes
0 answers

How to simulate an Appearance ("dark mode") change in React Native using Jest?

I am writing a puzzle app in React Native where the user can solve a puzzle by changing their device's Appearance to dark mode. I'm using React Native's Appearance module to accomplish this, by calling Appearance.getColorScheme() to get the initial…
3
votes
1 answer

mockConstructor(...): Nothing was returned from render while testing Tab Navigator

I am trying to test my bottomTabNavigator and have followed the instructions here : https://callstack.github.io/react-native-testing-library/docs/react-navigation but I am getting this error mockConstructor(...): Nothing was returned from render.…
3
votes
0 answers

Jest test cases failing due to timeout of react native test library

I am using jest for react-native test cases, after updating to jest v27.5.1, I started getting error for all of the async calls. I solved most of them by following this thread. After this I started getting issue from testing-library for…
3
votes
2 answers

react-native-testing-library with typescript does not work

I've tried for days many ways to set up @testing-library/react-native with typescript following a sort of guides but still not able to render a simple component. Roughly, my stack is react native with typescript and jest with ts-jest and…
1
2
3
11 12