title: Mock next/link with Jest in Next.js
body: <p>How to mock the Link component from &quot;next/link&quot; with jest in Next JS and check the redirect path after a click on a link element?</p>
  <p>Here an example component with a test:</p>
  <pre class="lang-js prettyprint-override"><code>import Link from &quot;next/link&quot;;
  
  export default function Nav() {
    return (
      &lt;div&gt;
        &lt;Link href=&quot;/login&quot;&gt;
          &lt;span&gt;Click here&lt;/span&gt;
        &lt;/Link&gt;
      &lt;/div&gt;
    )
  }
  </code></pre>
  <pre class="lang-js prettyprint-override"><code>describe(&quot;Nav&quot;, () =&gt; {
    it(&quot;redirects correctly&quot;, async () =&gt; {
    render(&lt;Nav /&gt;)
  
    fireEvent.click(screen.getByText(&quot;Click here&quot;));
  
    // check if redirect to href prop works as expected
  
    });
  });
  </code></pre>