Native Testing Library (@testing-library/react-native) is a testing library for React Native inspired by DOM Testing Library.
Questions tagged [native-testing-library]
8 questions
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…

Petro Ivanenko
- 637
- 2
- 8
- 19
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…

Petro Ivanenko
- 637
- 2
- 8
- 19
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 }…

Petro Ivanenko
- 637
- 2
- 8
- 19
2
votes
1 answer
How to test RN component rendering inside modal & portal in react native
I am using react-native-paper library as my UI component library.I am using Modal component which gets rendered inside Portal, something like below
....
For writing unit test cases I…

Lalit Kushwah
- 3,861
- 5
- 25
- 40
2
votes
1 answer
Check if first child renders nothing in Native Testing Library
Suppose I have the following component:
const MyComponent = () => null;
In React Testing Library (RTL), the following, AFAIK, should work:
const { container } = render( );
expect(container.firstChild).toBeEmpty();
where .toBeEmpty…

André Costa Lima
- 173
- 14
2
votes
2 answers
Difference between react-native-testing-library vs native-testing-library?
I want to test my React Native code, but I am struggling about which testing library I should use.
According to what I've read on the internet, it is a better practice to focus on testing the user behavior than the internal logic of a component.…

dng
- 411
- 1
- 5
- 18
0
votes
0 answers
jest-native toBeOnTheScreen
Why would you ever need to use the toBeOnTheScreen matcher from jest-native. https://github.com/testing-library/jest-native#tobeonthescreen My understanding is in the example within the docs the getByTestId would simply error if the 'child' element…

Scott w
- 495
- 7
- 15
0
votes
1 answer
TouchableOpacity does not show disabled and activeOpacity props
I am trying to test this simple button:
import React, { FC, ReactNode } from 'react';
import { TouchableOpacity, GestureResponderEvent, ViewStyle } from 'react-native';
type Props = {
style: ViewStyle;
onPress: (event: GestureResponderEvent) =>…

Petro Ivanenko
- 637
- 2
- 8
- 19