UNPKG

@amsterdam/design-system-react

Version:

All React components from the Amsterdam Design System. Use it to compose pages in your website or application.

47 lines (46 loc) 2.27 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { render } from '@testing-library/react'; import { createRef } from 'react'; import { Link } from './Link'; import '@testing-library/jest-dom'; describe('Link', () => { const linktext = 'Linktext'; it('renders with href attribute', () => { const { container } = render(_jsx(Link, { href: "#", children: linktext })); const link = container.querySelector('a:only-child'); expect(link).toBeInTheDocument(); expect(link).toHaveAttribute('href', '#'); }); it('renders standalone variant', () => { const { container } = render(_jsx(Link, { href: "#", children: linktext })); const link = container.querySelector('a:only-child'); expect(link).toHaveClass('ams-link'); }); it('renders inline variant', () => { const { container } = render(_jsx(Link, { href: "#", variant: "inline", children: linktext })); const link = container.querySelector('a:only-child'); expect(link).toHaveClass('ams-link ams-link--inline'); }); it('renders an additional class name', () => { const { container } = render(_jsx(Link, { className: "large" })); const link = container.querySelector(':only-child'); expect(link).toHaveClass('large'); expect(link).toHaveClass('ams-link'); }); it('renders the class name for contrast color', () => { const { container } = render(_jsx(Link, { color: "contrast", href: "#", children: linktext })); const link = container.querySelector('a:only-child'); expect(link).toHaveClass('ams-link ams-link--contrast'); }); it('renders the class name for inverse color', () => { const { container } = render(_jsx(Link, { color: "inverse", href: "#", children: linktext })); const link = container.querySelector('a:only-child'); expect(link).toHaveClass('ams-link ams-link--inverse'); }); it('supports ForwardRef in React', () => { const ref = createRef(); const { container } = render(_jsx(Link, { href: "https://example.com/", ref: ref, children: 'https://example.com/' })); const link = container.querySelector(':only-child'); expect(ref.current).toBe(link); }); });