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
0
votes
0 answers

Error when testing NativeBase component with jest

I'm receiving the following errors when trying to perform component tests using Jest, Testing Library React Native, and Native Base. If I pass the initialWindowMetrics property as stated in the documentation, I receive the following error: Element…
0
votes
1 answer

Installing react-native-testing-library gives react peer dependency error when I have a compatible react version

I get this error when I try to install react-native-testing-library (using expo for my project), which tells me I need react@>=16.8.0, but I have react@18.1.0, so shouldn't this be fine? Am I misunderstanding the error message?
0
votes
1 answer

Jest tests fail at useState or useEffect but not useContext or useNavigation

I have an expo react-native web component that renders fine on web but fails under test: import React, { useState, useEffect } from "react"; import { View } from "react-native"; const timePickerWeb = (date: Date, setDate:…
0
votes
1 answer

How to achieve 100% in unit testcase writing for React native functional component?

I have tried to write test case using jest as matcher and React NativeTesting library as a test base. But I can't reach the 100% test coverage. I have tried to mock the use effect and use state hooks but I won't mock that still it's asking for to…
0
votes
1 answer

Test Platform rendering in react native

I wondering how can I test this kind of code with react native testing library? const Component = () => ( {Platform.select({ ios: (
0
votes
2 answers

Querying conditionally rendered elements in react native jest which are rendered after a state update and not after an event

I want to query an element through jest which is conditionally rendered. The component is rendered after loading state is set to false when Api call is complete. There are ways to query elements which are rendered after an event such as button press…
0
votes
1 answer

How to test a component that renders asynchronously after a call

Suppose I have a component that loads its content when an asynchronous call returns succesfuly: const MyScreen = () => { let userData: userDataResponse; const [email, setEmail] = useState(""); const [firstTime, setFirstTime] =…
Rafael
  • 2,413
  • 4
  • 32
  • 54
0
votes
1 answer

When installing React Native Testing Library on an Expo project (uses React 18) I get an error

I have an Expo App (the last expo which uses React 18) that I want to run some testing on But when trying to install React Native Testing Library, I get this error: I wonder if this error means that it is incompatible with React 18 What do you…
Rafael
  • 2,413
  • 4
  • 32
  • 54
0
votes
0 answers

React Native Test : Nock and Testing Library

I am trying to do screen testing with react native while mocking the api responses with Nock. After a call to the api my component is supposed to display some text fields. It works on the app but I can't make the test working. Here is the component…
Antoine Grenard
  • 1,712
  • 3
  • 21
  • 41
0
votes
0 answers

Component that I am trying to test renders another component that lazy imports svgs. Because of the lazy import the test runs indefinitely

I have the following Icon component: const Icon: FunctionComponent = ({ icon, ...rest }) => { const LazyLoadedIcon = Icons[icon as IconType]; return ; }; And the following list of lazy loaded…
0
votes
1 answer

Jest failed because it cannot find text of rendered button

I very new to writing tests. Basically I want to test if the menu opens up when clicking it. The options are buttons with the text "Edit" and "Delete". Test fails with "Unable to find an element with text: Edit" MealCard.test.tsx /** *…
0
votes
0 answers

Testing a react-native component with jest

I'm working on a react-native project and I want to do some testing on it using the testing-library for react-native and jest. The issue is that I cannot render components that contain the Pressable component from react-native. Here is the component…
0
votes
0 answers

TypeError: config.headers.has is not a function

Getting errors when executing test cases in Redux Tool Kit query, Used React Native Testing Library for rendering components. An unhandled error occurred processing a request for the endpoint "getProducts". In the case of an unhandled error,…
0
votes
1 answer

Jest (ESM) can't import React Native components

Trying to use Jest with ESM configuration to test React Native components and getting errors that Jest can't parse the imports from 'react-native'. The errors look like this: SyntaxError: The requested module 'react-native' does not provide an…
nerdlinger
  • 1,610
  • 2
  • 17
  • 24
0
votes
0 answers

Generator function is not calling api in redux saga in unit tests

I am testing react native app using jest and react native testing library which uses redux saga for api calls.Below is my generators and watchers. //dispatch action deleteStock: stock => { console.log(stock); dispatch({type:…