import { render, screen } from '@testing-library/react';
import ExternalLink from '../external-link';
describe('ExternalLink component', () => {
it('should render external link with icon', () => {
const { asFragment } = render(
Link text
);
expect(asFragment()).toMatchSnapshot();
expect(screen.queryByTestId('external-link-icon')).toBeInTheDocument();
});
it('should render external link without target: _blank attribute', () => {
const { asFragment } = render(
Link text
);
expect(asFragment()).toMatchSnapshot();
});
it('should render just the url without http(s), www, /$ if no child text is passed', () => {
const { asFragment } = render(
);
expect(asFragment()).toMatchSnapshot();
});
it('should not include icon if noIcon is passed', () => {
render();
expect(screen.queryByTestId('external-link-icon')).not.toBeInTheDocument();
});
it('should not render anchor tag if no url', () => {
render(foo);
const el = screen.queryByText('foo');
expect(el).toBeInTheDocument();
expect(el?.tagName.toLowerCase()).not.toBe('a');
});
});