Not sure why this is happening when the docs say it's okay to use this: https://www.tabnine.com/code/javascript/functions/%40testing-library%2Freact-native/waitForElement
App.test.tsx
import React from 'react';
import { waitFor, waitForElement } from '@testing-library/react-native';
import renderer from 'react-test-renderer';
import App from './App';
jest.useFakeTimers();
describe('App initialized', () => {
it('has 1 child', async () => {
const Element = await waitForElement(() => renderer.create(<App />).toJSON() as any);
await waitFor(() => {
expect(Element).not.toBeNull();
expect(Element.children.length).toBe(1);
});
});
});
App.tsx
import React, { useEffect } from 'react';
import { NavigationConductor } from '@app/navigation';
import { useLoadingStore } from '@app/stores';
export default function App() {
// variables
const { appStartInitializeData } = useLoadingStore(store => store);
// setup
useEffect(() => {
appStartInitializeData();
}, []);
// render
return <NavigationConductor />;
}
Use waitFor
instead. waitForElement
has been renamed a while ago.
See Migration to 7.0 for details.