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
1
vote
2 answers

Unable to find an element with a testID

I'm building a React Native app. Within my GigsByDay component, there is a TouchableOpacity element which, when pressed, directs the user to a GigDetails screen. I'm trying to test this particular functionality using Jest and React Native Testing…
Josh Simon
  • 159
  • 1
  • 10
  • 27
1
vote
0 answers

How do I test a conditionally rendered component in React Native?

I'm building a React Native app that lists live music gigs. The user can toggle between showing the current day's gigs or the current week's gigs. If the user presses the 'Gigs Today' button, the state variable showWeek is set to false; if the 'Gigs…
1
vote
1 answer

How to get method instance in component after @testing-library/react-native render

SplashScreen is a React Native 0.70 component. generatePrivateKey.After rendering the component SplashScreen in jest 0.29, how to get the instance of method generatePrivateKey for further testing? The code below does not work import React from…
1
vote
2 answers

Test suite failed to run. Cannot find module '@testing-library/jest-native' running a test using react native testing library

I am running a test for a component that needs to check if it has a particular CSS style. As the React Native Testing Library doesn't have this function by default, I installed the @testing-library/react-native to use toHaveStyle from there but…
1
vote
0 answers

await act( async () ...) call throws error which says to use await with act

The following hook should be tested. export function useSomethingSaver() { let somethingMutation = useMutation(async (newSomething) => { return await saveSomething(newSomething) }) return { saveSomething: somethingMutation.mutate, …
1
vote
1 answer

Get the selected value of Native Base Select component in test

I'm trying to test my Select component from Native Base and in the test I select an item from the list or directly trigger the onValueChange prop with a value and then assert the selected value, but I can't find the prop that holds the selected…
1
vote
1 answer

Unable to find an element with testID in react native testing library

I am trying to findByTestId an IconButton (from React native Paper) but I get this error : Unable to find an element with testID: home-settings-button 84 | fireEvent.press(loginButton); 85 | > 86 | const settingsButton = await…
1
vote
0 answers

Error in render testing react native when require image

I'm doing render testing of a login screen that returns an error when an image is on the screen and I don't know what to solve test code it('render screen Login ', () => {render();}); return error 125 | 126 | …
1
vote
1 answer

How to test useFocusEffect with react-native-testing-library?

I use useFocusEffect from @react-navigation/native and I try to test the component. I tried what @meshantz suggested on react-navigation-hooks: How to test useFocusEffect but when I run the tests it says Cannot read property 'Provider' of…
1
vote
0 answers

typeError: cannot read properties of null (reading 'props'). react native testing library

I wanted to test if i click the button, it would navigate to login screen with react native testing library but i am unable to do it. the error was typeError: cannot read properties of null (reading 'props'). here is my…
1
vote
1 answer

How to execute onPress on TouchableOpacity react-native using jest and @testing-library/react-native?

I have a component called Header that look like this: import React from 'react' import {StyleSheet, TouchableOpacity, View, StyleProp, ViewStyle} from 'react-native' import {Text} from '..' import Icon from…
1
vote
0 answers

I can't render @react-navigation's NavigationContainer in tests using react native testing library

When I try to test my entire application, I'm receiving this error (full log at the end): Screen(...): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null. The test that is…
1
vote
0 answers

Unable to test combination of useEffect and setTimeout using Jest

Trying to assert a simple state change made using useEffect and setTimeout. The effect calls setTimeout with a value of 1500ms which should change the displayed string from 'unchanged' to 'changed'. component import * as React from 'React'; import…
1
vote
0 answers

how can I test when I press a button to action a navigate function?

I want to test my profile page. How can I test it when I press a button and navigate it with test? I get this error: TypeError: Cannot read properties of undefined (reading 'onPress') if(!data) { function navigateToAuth(isLogin: number): void…
universe11
  • 703
  • 1
  • 11
  • 35
1
vote
0 answers

Testing react native component that calls custom hook inside with jest and testing library

I am trying to write tests for my react native application for the first time. I have a component LoginForm that calls a hook useLoginForm inside of it, which is written like so: //LoginForm.js import { useLoginForm } from './hooks'; //more imports…