Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6212

How test a function that has been called or not in jest

$
0
0

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


Viewing all articles
Browse latest Browse all 6212

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>