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

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 Component() {  const [qrCode, setQrCode] = useState("initialUrl");const regenerate = () => {   getUrl = ApiCall;   serQrCode(getUrl);}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 6213

Trending Articles