import { render, screen } from '@testing-library/react'; import Link from './Link'; describe('Link', () => { test('Link handles onClick callback', () => { const mockOnClick = jest.fn< [ { dangerouslyDisableOnNavigation: () => void; event: React.MouseEvent | React.KeyboardEvent; }, ], // @ts-expect-error - TS2344 - Type 'undefined' does not satisfy the constraint 'any[]'. undefined >(); render( Link , ); screen.getByText('Link').click(); expect(mockOnClick).toHaveBeenCalled(); }); it('renders a link with correct new tab announcement with and without accessibilityLabel', () => { render( Visit Pinterest , ); expect( screen.getByText('Visit Pinterest', { exact: true, }), ).toBeVisible(); expect( screen.getByTitle(', Opens a new tab', { exact: true, }), ).not.toBeVisible(); render( , ); expect(screen.getByLabelText('Visit Pinterest; Opens a new tab')).toBeVisible(); }); it('renders with data-test-id', () => { const TEST_ID = 'link-test-123'; render( , ); expect( screen.getByTestId(TEST_ID, { exact: true, }), ).toBeVisible(); }); });