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
3
votes
2 answers

Testing React Native app: How to fix: navigation.setOptions is not a function?

Here is the test: describe('', () => { it('Renders correctly', () => { // const setOptions = jest.fn(); // 1 // const setOptions = (navigation: any, route: any) => { } // 2 // const setOptions = (props: HomeProps) => { } // 3 // …
3
votes
1 answer

react native typescript screen test returning Test suite failed to run. Error react-native-permissions: NativeModule.RNPermissions is null

I am experiencing difficulty writing tests for react-native that involve mocking Internet and Vibration permissions written in typescript using instructions from the URL below How to mock PermissionAndroid from react native I keep getting the below…
3
votes
3 answers

Jest mock dimensions not changing

I am doing testing for the first time so I am pretty much sure that I am doing something wrong. I was writing test case and my component does this internally. const {width, height} = Dimensions.get('window') For my test case, I was considering…
3
votes
0 answers

How to properly configure jest unit and component tests in React Native monorepo with TypeScript

So, my issue is a bit difficult to descibe because our repository (which is at work, so I unfortunately can't just provide a link to it) is pretty big and complex, but I'll do my best. First of all, the problem: The Problem I run jest and the result…
3
votes
0 answers

How to unit test function in ImagePicker Expo using React native testing library?

I have this code below in react-native using expo, which is a button, click on the button will call ImagePicker.requestMediaLibraryPermissionsAsync(), if the permission is granted, then call to ImagePicker.launchImageLibraryAsync() to let user pick…
ken
  • 2,426
  • 5
  • 43
  • 98
3
votes
0 answers

fireEvent.press not working (React Native Testing Library)

I am writing unit tests for my React Native project. My main screen is WelcomScreen.js and inside it is following custom button created using TouchableOpacity:
3
votes
0 answers

react native testing library, No instances found with testID

Im getting the error, No instances found with testID: CreateAccount.errorMessage But Im referencing the ID on "CreateAccount.js" Then on…
3
votes
1 answer

Test setTimeout with React Native Testing Library and Jest

I have a React Native app with the following Player component that infinitely calls a play() function with a setTimeout. I'm using react-native-testing-library for rendering/testing along with jest. I am trying to test this setTimeout function.…
Cannon Moyer
  • 3,014
  • 3
  • 31
  • 75
3
votes
0 answers

React native @5Navigation react testing library

I am new to React Native Testing Library. For my React native app I am using styled components and Typescript. I fetched the data and pass to my flatList. In Flat-list's render item I have created one global component where it display all the data…
3
votes
2 answers

How to mock useEffect async calls with react-native-testing-library?

I'm trying to test the screen that has useEffect hook with the following: export const SomeScreen: React.FC = ({}) => { const [isSensorAvailable, setIsSensorAvailable] = useState(false); useEffect(() => { const…
3
votes
1 answer

Testing onScroll event in FlatList

I have been trying to test onScroll event of a FlatList, with this very simple test files: Test file: // @ts-nocheck import React from 'react'; import { fireEvent, render } from '@testing-library/react-native'; import { MyComponent } from…
3
votes
1 answer

How to test react-native methods?

I want to test Vibration module of react-native, the problem is that I get an error when I try to test it: With this component: import React, { useEffect } from 'react'; import { Text, Vibration } from 'react-native'; interface Props {} export…
3
votes
1 answer

Test focus of element

How do I check that this TextInput component is focused? I know how to do it on the web: const input = getByPlaceholderText("placeholder"); expect(document.activeElement).toEqual(input); But how to do the same in React Native? it('should have…
3
votes
0 answers

onChangeText is called event when editable is false

This issue says that fireEvent.changeText event should not call onChangeText function when editable is false, yet when I run this: import React from 'react'; import { fireEvent, render } from '@testing-library/react-native'; import { TextInput }…
3
votes
0 answers

How to test if Modal (react-native) is visible or not using Jest?

Modal also does not have a testID prop. Also, I'm using Modal from 'react-native' and not 'react-native-modal'
1 2
3
11 12