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 › ...
2
votes
0
answers
278
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:
...
0
votes
0
answers
144
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
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
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 ...
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 ...
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 ...
0
votes
2
answers
901
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 /&...
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 ...
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';
...
1
vote
1
answer
580
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 ...
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}...
0
votes
1
answer
387
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 ...
2
votes
1
answer
883
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
646
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 ...
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>) ...
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 ...
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("...
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.
...
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 ...
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 ...
2
votes
1
answer
407
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
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
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 ...
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/...