samedi 27 juin 2020

Mocking useState hook to test component/passing data to my test

I have the following component I'm trying to test. The GoogleLogin component is coming for a third party library but I'm just wondering how I can test the loading part? I want to set/mock the loading data and test if the loading component is shown on screen.

const GoogleLoginButton: React.FC = () => {
    const [googleLoading, setGoogleLoading] = useState<boolean>(false)

    const googleResponseSuccess = () => {
        setGoogleLoading(false)
    }

    const googleResponseError = () => {
        setGoogleLoading(false)
    }

    return (
        <>
            {googleLoading && <InlineLoader />}

            <GoogleLogin
                onSuccess={googleResponseSuccess}
                onFailure={googleResponseError}
            />
        </>
    )
}

Does anybody have a good way of doing this? any help would be appreciated!

Aucun commentaire:

Enregistrer un commentaire