toBeOnTheScreen() not Working With React-Native
komalharmale opened this issue · 5 comments
react-native
orexpo
:@testing-library/react-native
version:jest-preset
:react-native
version:node
version:
Relevant code or config:
const your = (code) => 'here';
What you did:
What happened:
Reproduction:
Problem description:
Suggested solution:
Can you help us fix this issue by submitting a pull request?
I have create one simple component in that I have writen the code for single button
return(
List of numbers from 1 to 20
<TouchableOpacity
testID='button'
onPress={()=>navigation.navigate('Dashboard')}
style={styles.submitcontainer}>
<Text style={{color:'#FFFFFF',backgroundColor:'blue'}}>Go To Login Screen
);
}
This is my test.js file where i am trying to check is element is available on screen or not but jest is throwing error while running the command
render();
const child = screen.getByTestId('child')
expect(child).toBeOnTheScreen();
const header = await screen.findByText('List of numbers from 1 to 20');
expect(header).toBeOnTheScreen();
getting output:
FAIL tests/Profile-test.js (5.502 s)
● find element and check navigating properly to next page
TypeError: expect(...).toBeOnTheScreen is not a function
34 | render(<Profile/>);
35 | const child = screen.getByTestId('child')
> 36 | expect(child).toBeOnTheScreen();
| ^
37 | const toClick = await screen.findByText('Go To Login Screen');
38 | const header = await screen.findByText('List of numbers from 1 to 20');
39 | // expect(header).toBeOnTheScreen();
at Object.<anonymous> (__tests__/Profile-test.js:36:17)
at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:22:9)
at node_modules/@babel/runtime/helpers/asyncToGenerator.js:27:7
at tryCallTwo (node_modules/promise/lib/core.js:45:5)
at doResolve (node_modules/promise/lib/core.js:200:13)
at new Promise (node_modules/promise/lib/core.js:66:3)
at Object.<anonymous> (node_modules/@babel/runtime/helpers/asyncToGenerator.js:19:12)
nothing works
@komalharmale I am unable to understand the exact issue you are facing. Could you use RNTL basic example app to build a minimal reproduction repository that showcases your issue?
@komalharmale Closing as not actionable without response from OP.
I got this error as well using latest version of the libraries
@mdjastrzebski @thespacemanatee I was facing above issue because of I forgot to install 'testing-libraty/jest-native` library.
Now it's working as expected.