title: React-testing library: test router redirect
body: <p>How do I test that the router link changed after a redirect?</p>
  
  <p>After clicking on a button, it should redirect to another page with url ending in "new_page".</p>
  
  <p>This is what I tried, but I keep getting undefined.</p>
  
  <pre><code>  {getByTestId} = render(&lt;MyButton /&gt;);      
  
    const mockBoxIconButton = getByTestId('box-icon-button');
  
    mockBoxIconButton.click();
  
    console.log(getByTestId('box-icon-button').closest('a')); # undefined
    console.log(getByTestId('box-icon-button').location.href);  # undefined
  
    expect(
      mockExtractionButton.getByTestId('box-icon-button').closest('a')
    ).toHaveAttribute('href', /http[a-zA-Z0-9:\/-]*new_page/);
  });
  </code></pre>