182 questions
1
vote
0
answers
66
views
SyntaxError: C:\zero\node_modules\react-native\Libraries\Components\Touchable\TouchableOpacity.js: Missing initializer in const declaration
I'm trying to write tests for my React Native app (using TypeScript). All my unit tests pass without issues, but when writing component tests, I encounter the following error:
● ButtonComponent › ...
0
votes
0
answers
34
views
Test react-hook-form with react-native-testing-library error
I am trying to test an input value in my form, my form also contains a drop down list component - I keep getting the warning:
Warning: Function components cannot be given refs. Attempts to access ...
2
votes
0
answers
284
views
Issue with @testing-library after adding Select component from gluestack-ui v.2
I'm facing an issue where my test fails to find an element by text after I added the Select UI component from gluestack-ui to my React Native component.
Before adding the Select, my test works fine:
...
2
votes
0
answers
126
views
ReferenceError: expect is not defined ( react-native , @testing-library/react-native )
I have been facing two issues mainly
console.error
Warning: React.createElement: type is invalid -- expected a string (for built-in
components) or a class/function (for composite components) but ...
0
votes
0
answers
147
views
How to handle react component being unmounted on user press in unit testing
I am writing Jest tests for my react native application. When I use user.press function, I get the following error:
Unable to find node on an unmounted component.
at findCurrentFiberUsingSlowPath (...
1
vote
0
answers
213
views
How to fix jest error Cannot find module '../Utilities/Platform' from 'node_modules/react-native/Libraries/StyleSheet/processColor.js'
I want to running jest to test my component, I'm using React Native Testing Library to test and React Native Web to create an example. Whenever I tried to run jest I facing an error like this:
● Test ...
-1
votes
1
answer
302
views
Getting error in Component testing - Jest & react-native testing library
Getting error when using the render method to test component
`Trying to detect host component names triggered the following error:
Unexpected token 'export'
There seems to be an issue with your ...
0
votes
1
answer
506
views
How can I change a TextInput's selection and fire its onSelectionChange event in unit testing?
I have a React Native component with a TextInput that I'm testing. Part of the behaviour of this component relies on handling the current selection position via onSelectionChange — that is, it matters ...
0
votes
1
answer
220
views
TouchableOpacity fails on second render with React Native Testing Library
When I test component containing TouchableOpacity with React-Native testing library, first time render is ok, second time in test suite test always fails.
If I replace TouchableOpacity with ...
2
votes
0
answers
934
views
React Native testing library "`render` method has not been called" occurs sporadically
We just recently did a React Native upgrade to 0.72.4 on our project and therefore updated the versions of the testing libraries as well. These are the versions they're at right now:
Relevant ...
0
votes
2
answers
683
views
getAllByRole does not find input element in react native testing library
I have a simple component with two inputs and one button. I was able to test the code with getAllByRole func for buttons. But when I want to find input elements, I got below error :
Unable to find an ...
4
votes
1
answer
2k
views
babel config setup for testing
I have setup testing in my react native app with typescript using React-native-testing-library. I have configured my babel,config.js as below. There is an odd issue though.
module.exports = {
...
3
votes
1
answer
5k
views
React Native Unit Testing - Can't access .root on unmounted test renderer
Hello I'm testing my app with react-native-testing-library. When i run test returning test fail How can i solve this? Error is:
Can't access .root on unmounted test renderer
There seems to be an ...
1
vote
1
answer
320
views
React Native Unit Testing [closed]
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 ...
0
votes
2
answers
911
views
Cannot Find TestID for react-native Unit test cases, following is the description for the same
Test Case:
it("Test Email text by test id" , () => {
const testIDName='email-title';
const {getByTestId} = render(
<Provider store={store}>
<NavigationContainer><Login /&...
2
votes
0
answers
292
views
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-...
0
votes
1
answer
172
views
@testing-library/react-native mock axios post timesHaveBeenCalled(1) is 0
I need help figuring out how to mock an axios post request. The docs have failed me. I've tried just about every combination I could find on stack overflow. All end up with either typescript errors or ...
1
vote
1
answer
1k
views
@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/...
0
votes
1
answer
263
views
JEST test passes, act not correctly used?
I do some unit testing, here is my code:
import React from 'react';
import { render, fireEvent, act, waitFor } from '@testing-library/react-native';
import { LoginScreen } from '../login.screen';
...
37
votes
2
answers
80k
views
Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax
I'm using ignite to create an expo react native app. I'm using this guide https://ignitecookbook.com/docs/recipes/GeneratorComponentTests to create component test files
Here is the first test file
...
1
vote
1
answer
587
views
Having trouble to test my component with ref using react-native-testing-library and react-native-reanimated
I am trying to test my toast component (uses react-native-reanimated under the hood) using react-native-testing-library but when I try to show my toast the ref is null. I cannot understand why:
This ...
0
votes
1
answer
834
views
How to write unit test for React Native Switch's value prop
I am using React Native Switch. I want to write a unit test (using jest and testing-library/react-native) for its value prop. But there is no value in its props
My use case is there will be a default ...
1
vote
0
answers
1k
views
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:
<FlatList
testID={LIST_OF_TRANSACTIONS}...
1
vote
1
answer
2k
views
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 ...
0
votes
1
answer
390
views
Installing react-native-testing-library gives react peer dependency error when I have a compatible react version
I get this error when I try to install react-native-testing-library (using expo for my project), which tells me I need react@>=16.8.0, but I have [email protected], so shouldn't this be fine? Am I ...
1
vote
0
answers
403
views
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 ...
2
votes
1
answer
886
views
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 ...
0
votes
1
answer
2k
views
Jest tests fail at useState or useEffect but not useContext or useNavigation
I have an expo react-native web component that renders fine on web but fails under test:
import React, { useState, useEffect } from "react";
import { View } from "react-native";
...
0
votes
1
answer
647
views
How to achieve 100% in unit testcase writing for React native functional component?
I have tried to write test case using jest as matcher and React NativeTesting library as a test base. But I can't reach the 100% test coverage.
I have tried to mock the use effect and use state hooks ...
0
votes
1
answer
431
views
Test Platform rendering in react native
I wondering how can I test this kind of code with react native testing library?
const Component = () => (
<View style={styles.iconWrapper}>
{Platform.select({
ios: (
<...
1
vote
0
answers
37
views
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(<Text >hey</Text>) ...
4
votes
1
answer
4k
views
Testing with jest and React Native Testing Library
I’m a newbie with testing
I’m trying to get a grip on testing React Native with Expo, Jest and React Native Testing Library
I wrote a simple screen that takes data from an API and writes the first ...
0
votes
2
answers
83
views
Querying conditionally rendered elements in react native jest which are rendered after a state update and not after an event
I want to query an element through jest which is conditionally rendered. The component is rendered after loading state is set to false when Api call is complete. There are ways to query elements which ...
1
vote
0
answers
54
views
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 ...
0
votes
1
answer
34
views
How to test a component that renders asynchronously after a call
Suppose I have a component that loads its content when an asynchronous call returns succesfuly:
const MyScreen = () => {
let userData: userDataResponse;
const [email, setEmail] = useState("...
1
vote
0
answers
583
views
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 ...
3
votes
1
answer
2k
views
React Native Testing Library: scroll FlatList to bottom
I have a react-native FlatList component with onEndReached event used to load more items.
I am testing the component with react-native-testing-library. The test is as follows:
Component mounted.
...
0
votes
1
answer
194
views
When installing React Native Testing Library on an Expo project (uses React 18) I get an error
I have an Expo App (the last expo which uses React 18) that I want to run some testing on
But when trying to install React Native Testing Library, I get this error:
I wonder if this error means that ...
1
vote
2
answers
2k
views
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 ...
-1
votes
1
answer
839
views
jest multistep form testing - is it possible to split the test into multiple tests but with one render?
I have a multi-step Sign Up form in my React Native application and I'm testing it with jest and RNTL. It works fine, but I just don't like how it looks.
Now it's just one big test function which ...
0
votes
1
answer
308
views
React Native Test : Nock and Testing Library
I am trying to do screen testing with react native while mocking the api responses with Nock. After a call to the api my component is supposed to display some text fields. It works on the app but I ...
1
vote
0
answers
155
views
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 ...
2
votes
1
answer
408
views
How do I unit test a filter function in React Native?
I'm building a live music gig listing app in React Native with expo.
An array of gig objects is fetched from firebase, with the following shape:
gigs:
[
{
dateAndTime:{seconds:2345234748},
...
1
vote
1
answer
2k
views
Jest failed because it cannot find text of rendered button
I very new to writing tests. Basically I want to test if the menu opens up when clicking it. The options are buttons with the text "Edit" and "Delete". Test fails with
"Unable ...
-1
votes
1
answer
852
views
How to mock a state value in jest
A react native 0.70 component displays items in FlatList. The array items is a state and is assigned value in hook useEffect. I would like to jest (0.29) it to see if a item's name is shown up on ...
1
vote
1
answer
1k
views
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 ...
1
vote
1
answer
474
views
Jest (ESM) can't import React Native components
Trying to use Jest with ESM configuration to test React Native components and getting errors that Jest can't parse the imports from 'react-native'. The errors look like this: SyntaxError: The ...
3
votes
1
answer
1k
views
React native elements with jest not working
I'm using @testing-library/react-native but when I try to test a component that has any rneui: 4.0.0-rc-6 components I get several errors:
The first now was
Details:
/Users/ep/myProject/...
2
votes
2
answers
7k
views
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/...
0
votes
2
answers
962
views
Finding the buttons on the screen that have no text for the test
I am trying to write the tests for the NavBar component (using react-native-testing-library) that has several buttons that are basically just icons (using ui-kitten for react native). So I can't get ...