title: Mocking react custom hook
body: <p>I need to mock useLogin hook, bacause it contains logic that throws an error. Later i will test it in isolationю. UseLogin returns loading flag and login function that connecting new user to firebase.</p>
  <pre><code>import useLogin from &quot;../../../hooks/useLogin&quot;;
  
  export default function Login({ register, handleSubmit }) {
    const [loading, login] = useLogin();
  
    return (
      &lt;Form onSubmit={handleSubmit(login)}&gt;
      {...other components}
      &lt;Form&gt;
    );
  }
  </code></pre>
  <p>useLogin hook</p>
  <pre><code>import { useState } from &quot;react&quot;;
  import { useHistory } from &quot;react-router&quot;;
  import { useModalContext } from &quot;../../context&quot;;
  
  import { firebase } from &quot;../../libs/firebase&quot;;
  
  export default function useLogin() {
    const [loading, setLoading] = useState(false);
    const [, { showErrorModal }] = useModalContext();
    const history = useHistory();
  
    function login({ email, password }) {
      setLoading(true);
      firebase
        .auth()
        .signInWithEmailAndPassword(email, password)
        .then(() =&gt; {
          setLoading(false);
          history.push(&quot;/&quot;);
        })
        .catch(() =&gt; {
          setLoading(false);
          showErrorModal(&quot;User not found&quot;);
        });
    }
  
    return [loading, login];
  }
  </code></pre>