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 issue with your configuration that prevents React Native Testing Library from working correctly.
Please check if you are using compatible versions of React Native and React Native Testing Library.
Can't access .root on unmounted test renderer
React Version : "react": "18.2.0"
React Native Version : "react-native": "0.72.3"
React Native Testing Library Version : "@testing-library/react-native": "^12.2.2"
Testing Library Jest Native Version : "@testing-library/jest-native": "^5.4.3"
I have this test code;
describe('LoginScreen', () => {
it('should render the LoginScreen component', async () => {
await act(async () => {
render(
<Provider store={store}>
<LoginScreen />
</Provider>,
);
});
const loginScreen = getByTestId('login-screen');
expect(loginScreen).toBeTruthy();
});
});
Test code result is;
FAIL __tests__/login.screen.test.js
LoginScreen
✕ should render the LoginScreen component (5 ms)
● LoginScreen › should render the LoginScreen component
Trying to detect host component names triggered the following error:
Can't access .root on unmounted test renderer
There seems to be an issue with your configuration that prevents React Native Testing Library from working correctly.
Please check if you are using compatible versions of React Native and React Native Testing Library.
8 | it('should render the LoginScreen component', async () => {
9 | await act(async () => {
> 10 | render(
| ^
11 | <Provider store={store}>
12 | <LoginScreen />
13 | </Provider>,
at detectHostComponentNames (node_modules/@testing-library/react-native/src/helpers/host-component-names.tsx:52:11)
at detectHostComponentNames (node_modules/@testing-library/react-native/src/helpers/host-component-names.tsx:27:30)
at renderInternal (node_modules/@testing-library/react-native/src/render.tsx:49:40)
at renderInternal (node_modules/@testing-library/react-native/src/render.tsx:32:10)
at __tests__/login.screen.test.js:10:13
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 node_modules/@babel/runtime/helpers/asyncToGenerator.js:19:12
at callback (node_modules/@testing-library/react-native/src/act.ts:31:24)
at act (node_modules/react/cjs/react.development.js:2512:16)
at actImplementation (node_modules/@testing-library/react-native/src/act.ts:30:25)
at Object.<anonymous> (__tests__/login.screen.test.js:9:14)
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 Object.<anonymous> (node_modules/@babel/runtime/helpers/asyncToGenerator.js:19:12)
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 0.931 s, estimated 1 s
Ran all test suites.