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
1 answer

React Native Test if screen is visible jest @testing-library/react-native @react-navigation/native

I have the following test. See the comments for an explanation of the problem. describe('Cancel Button', () => { it('should navigate back to the previous screen', async () => { let { getByA11yLabel, findByText } = render(
1
vote
0 answers

Redux Toolkit, Testing createAsyncThunk actions with it's cycles

I am trying to test createAsyncThunk actions the same way I test createAction but it fails and nothing changes in the reducers. I have made a small app to simulate the cases I made createAsyncThunk and made some tests for it but unfortunately, any…
Snowflake
  • 191
  • 1
  • 2
  • 13
1
vote
1 answer

Is it really necessary to check if getBy or findBy methods returns truthy values?

I have some experience in frontend projects using testing-library, but definitely I'm not an expert. During the code review process on most of those projects, it was really common to find some test suites with this structure: // Original code:…
1
vote
0 answers

How to unit test Yup .test() method using React Native Testing Library?

I have a Formik from which is like this: // here if…
1
vote
3 answers

How to fix TypeError: navigation.setOptions is not a function

I'm trying to implement react native test library with jest to my app. For now I have a problem with the navigation on my component. When I'm running the test, I've got an error : TypeError: navigation.setOptions is not a function Here is my…
1
vote
1 answer

How to test React Native "Pressable" onPress function

Here is my react native code {signInLinkText} I want to write unit test case with react native testing library to test onPress function.…
Anshul Jain
  • 765
  • 7
  • 15
1
vote
0 answers

How to cover onPress for touchableOpacity in .map loop jest testing library

I'm trying to write test cases in React Native using Jest and Testing Library. I have a .map function where it renders a component with TouchableOpacity. {data.map((item, index) => (
Sai kiran
  • 237
  • 3
  • 15
1
vote
1 answer

How to properly test if a Toast has been shown in react native using native base?

I am trying to write a test that checks if the screen is showing a Toast with an error message. The test passes, but there is a warning: console.error Warning: You called act(async () => ...) without await. This could lead to unexpected…
1
vote
1 answer

React Native Testing Framework findBy doesn't find and waitFor doesn't wait

This is an image gallery and I'm confident it's working correctly. It runs fine in the simulator. I've tried to variations of the same test: test('main image should display', async () => { const { findByTestId } = render(
1
vote
0 answers

Unable to achieve 100% test coverage using @react-native-community/netinfo

I am trying to write unit test cases for the below code. However, I am not able to achieve 100% test-coverage. I am using @react-native-community/netinfo package to get the network connection information and @testing-library/react-native for writing…
1
vote
1 answer

Expo secure-store unavailable in jest tests

This question is specifically about expo-secure-store and jest. Currently, I am using expo-secure-store to store my JWT when logging in. It works fine when running on emulator however, it doesn't work at all in Jest tests; token comes back as…
1
vote
0 answers

React-Native-Testing-Library 'warning - an updated was not wrapped in act(...)

I think this question has been asked, but no solution was provided. I'm using RNTL trying to unit test a simple RN component. My example below: component = render(
1
vote
0 answers

@testing-library/react-native How should I test the BackHandler Alert and handle ok and cancel button?

Unable to test this below code using @testing-library/react-native useCallback(() => { const onBackPress = () => { Alert.alert("Hold on!", "Are you sure you want to Exit?", [ { text: "Cancel", …
1
vote
3 answers

Writing a unit test to check if the app is offline in react-native

I have the following component which displays a text on the app if the app is offline. import React from 'react'; import { useNetInfo } from '@react-native-community/netinfo'; import { Label } from 'components/ui'; const OfflineNotice = () => { …
1
vote
0 answers

Testing error: useSharedValue is not a function while testing

Description I'm using react-native-reanimated and when I'm testing, useSharedValue throws an error that it's not a function when using jest and react-native-testing-library. I've mocked react-native-reanimated by using the mock provided as part of…