This is my example code, here I need to test the regenerate function after component mounts and I need to make sure that qrCodeUrl has been changed or not for Qrcode component
export function generate() { const [qrCode, setQrCode] = useState("initialUrl");useEffect(() => { const regenerate = async () => { const qrCodeUrl = await someCall(); setQrCode(qrCodeUrl); }; regenerate(); }, [])return (<View testID="qrCodeWrapper"><Qrcode url={qrCode} /></View>)}
and this is my test file
test("Has to ensure that QR code is refreshed", async () => { const { environment, getByTestId } = render(Component); await resolveMostRecentOperation<ComponentQuery>(environment); const qrCodeWrapper = getByTestId("qrCodeWrapper"); expect(qrCodeWrapper.props.children).toBeDefined(); expect(qrCodeWrapper.props.children.props.url).toBe(`${appConfig.baseUrl}snapshot/initialUrl`); });
This test is working fine but I am unable to get the updated url after component mounts, it always showing initialUrl
lang: react-native, jest, @testing-library/react-native