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

React Native test failed when using Formik and Yup as validation schema

I am trying to write some tests for a React Native component built using Formik. It's a simple form asking for username and password, and I want to use a validation schema built using Yup. When I use the emulator and test the form manually, the form…
2
votes
1 answer

Testing react-native-testing-library with react-navigation v5

I'm looking to test react-navigation v5 with react-native-testing-library. The documentation says to do the following. import React from 'react'; import { NavigationContainer } from '@react-navigation/native'; import { render, fireEvent } from…
2
votes
1 answer

Jest + react-navigation not locating route / params

I am trying to write a test for an app using react-navigation and I am running into issues of the route and params being read correctly. I am getting an error of TypeError: Cannot read property 'params' of undefined on const [leadId] =…
2
votes
0 answers

Testing app containing AppLoading component

I am new to the world of unit testing and I have just began to write tests for my React Native (Expo) app. After doing research I have finally landed in using Jest and React Native Testing Library. Consider the following that uses the AppLoading…
faerin
  • 1,915
  • 17
  • 31
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.…
1
vote
1 answer

React Native Unit Testing

I have a few questions about react-native-testing-library. I want to implement unit tests on my app by using react-native-testing-library. I run my LoginScreen component using the render() method and check the rendering status of any component from…
1
vote
0 answers

How to avoid "AirGoogleMaps dir must be added to your xCode" while running tests on Expo?

I switched the react-native-maps provider to Google Maps on a React Native / Expo app. There's no issues when I run the app with Expo Go, but when opening the map on integration tests with react-native-testing library, I get the following…
1
vote
1 answer

@testing-library/react-native -> render -> "TypeError: Cannot read properties of undefined (reading 'exists')"

I've looked through many similar questions, but none seem to be facing the same issue I am having... ScreenLogin.test.tsx import React from 'react'; import { render, screen } from '@testing-library/react-native'; import ScreenLogin from…
Fiddle Freak
  • 1,923
  • 5
  • 43
  • 83
1
vote
0 answers

TestID on flatlist not showing up when testing with react-native-testing-library

I am trying to unit-test my flatlist to make ure a view pops up once the flatlist has scrolled a certain amount of distance. My flatlist looks like this:
1
vote
1 answer

how to test if a function was executed when clicking on the button?

I have implemented the component below, which is a card containing information about a product and a button that, when pressed, redirects the user to the details screen. export default function ProductItem(props: ProductItemProps) { const…
1
vote
0 answers

MSW Expect API Error with testing library fail assertion

I'm trying to test a failure on my API call with MSW, testing library and RTK Query. More on the context: I'm testing a hook and I'm calling a function and expect an API fail to assert that an error callback is call. This is the code, the test call…
1
vote
1 answer

Is the `user-event` library compatible with React Native Testing Library?

Can anyone confirm whether the user-event library is compatible with React Native Testing Library? I'm guessing not, as the user-event docs say the library can be used with any framework as long as there is a DOM and the React Native Testing…
Andrew
  • 3,825
  • 4
  • 30
  • 44
1
vote
0 answers

Error: React component type is invalid in LoginScreen.test.js file. Expected a string (for built-in components) or a class/function

LoginScreen.test.js import { Text } from 'react-native'; it("Login_Screen_should_render_correctly", () => { const { toJSON } = render(hey) expect(toJSON).toMatchSnapshot(); …
1
vote
0 answers

I have a component that I am trying to test, which utilises a hook that exports a function. How to mock the exported function before the test?

I have a hook called useStartGame which exports just 1 function like this: const useStartGame = () => { const startGame = (game) => { //Do something } return { startGame }; } Now I have a component which uses this hook, however, I want to…
Onyx
  • 5,186
  • 8
  • 39
  • 86
1
vote
0 answers

Testing a component that calls an external function with Jest and React Native Testing Library

Suppose I have a component that calls a function, for example: // AComponent.js import { Text, View } from "react-native"; import { getAString } from "./utils/function"; const AComponent = () => { return (