import { createRef } from 'react'; import { render, screen } from '@testing-library/react'; import IconButtonLink from './IconButtonLink'; describe('IconButtonLink', () => { it('handles click', () => { 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(); screen.getByRole('link').click(); expect(mockOnClick).toHaveBeenCalled(); }); it('renders with sequential keyboard navigation and forwards a ref to the innermost element', () => { const ref = createRef(); render( , ); expect(ref.current instanceof HTMLAnchorElement).toEqual(true); expect(ref.current instanceof HTMLAnchorElement && ref.current?.href).toEqual( 'http://www.pinterest.com/', ); expect(ref.current instanceof HTMLAnchorElement && ref.current?.tabIndex).toEqual(0); }); it('renders disabled', () => { const ref = createRef(); render( , ); expect(ref.current instanceof HTMLAnchorElement).toEqual(true); expect(ref.current instanceof HTMLAnchorElement && ref.current?.href).toEqual(''); expect(ref.current instanceof HTMLAnchorElement && ref.current?.href).toEqual(''); }); it('renders removed from sequential keyboard navigation via tabIndex', () => { const ref = createRef(); render( , ); expect(ref.current instanceof HTMLAnchorElement).toEqual(true); expect(ref.current instanceof HTMLAnchorElement && ref.current?.tabIndex).toEqual(-1); }); it('renders with correct new tab announcement with accessibilityLabel', () => { render( , ); expect(screen.getByLabelText('Visit Pinterest; Opens a new tab')).toBeVisible(); }); it('renders accessibilityLabel with no accessibilityLabel in Tooltip', () => { render( , ); expect(screen.getByLabelText('Share Pin with friends')).toBeVisible(); }); it('renders with data-test-id', () => { const TEST_ID = 'button-test-123'; render( , ); expect(screen.getByTestId(TEST_ID, { exact: true })).toBeVisible(); }); });