Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mocking next link with target="_blank" #125

Open
Mnigos opened this issue Jun 13, 2024 · 1 comment
Open

Mocking next link with target="_blank" #125

Mnigos opened this issue Jun 13, 2024 · 1 comment

Comments

@Mnigos
Copy link

Mnigos commented Jun 13, 2024

            <Link
              href={href ?? ''}
              target="_blank"
              className={className}
              {...props}
            >
             link
            </Link>
          </TooltipTrigger>
  test('should open in spotify', async () => {
    render(<OpenInSpotifyButton href={href} />, {
      wrapper: MemoryRouterProvider,
    })

    const user = userEvent.setup()

    await user.click(screen.getByRole('link'))

    expect(mockRouter.pathname).toEqual(href)
  })
AssertionError: expected '/' to deeply equal 'https://spotify.com'

- Expected
+ Received

- https://spotify.com
+ /
@chris-schneider-zen
Copy link

In this case it's probably best to assert the attributes on the link. Since the target is _blank it won't actually set the url of the current page, but open an entirely different one.

Eg:

const link = screen.getByRole('link');

expect(link).toHaveAttribute('href', '...');
expect(link).toHaveAttribute('target', '_blank');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants