UNPKG

@amsterdam/design-system-react

Version:

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

61 lines (60 loc) 2.62 kB
import { jsx as _jsx } from "react/jsx-runtime"; /** * @license EUPL-1.2+ * Copyright Gemeente Amsterdam */ import { render, screen } from '@testing-library/react'; import { createRef } from 'react'; import { describe, expect, it } from 'vitest'; import { ErrorMessage } from './ErrorMessage'; describe('ErrorMessage', () => { it('renders', () => { render(_jsx(ErrorMessage, {})); const component = screen.getByRole('paragraph'); expect(component).toBeInTheDocument(); expect(component).toBeVisible(); }); it('renders a design system BEM class name', () => { render(_jsx(ErrorMessage, {})); const component = screen.getByRole('paragraph'); expect(component).toHaveClass('ams-error-message'); }); it('renders an extra class name', () => { render(_jsx(ErrorMessage, { className: "extra" })); const component = screen.getByRole('paragraph'); expect(component).toHaveClass('ams-error-message extra'); }); it('renders a Dutch prefix by default', () => { render(_jsx(ErrorMessage, {})); const component = screen.getByText('Invoerfout', { exact: false }); expect(component).toBeInTheDocument(); }); it('renders a custom prefix', () => { render(_jsx(ErrorMessage, { prefix: "Error" })); const component = screen.getByText('Error', { exact: false }); expect(component).toBeInTheDocument(); }); it('supports ForwardRef in React', () => { const ref = createRef(); render(_jsx(ErrorMessage, { ref: ref })); const component = screen.getByRole('paragraph'); expect(ref.current).toBe(component); }); it('shows an icon', () => { const { container } = render(_jsx(ErrorMessage, {})); const iconWrapper = container.querySelector('.ams-icon'); const icon = container.querySelector('svg'); expect(iconWrapper).toBeInTheDocument(); expect(icon).toBeInTheDocument(); }); // TODO: we can't currently test this, because we can't pass a class or anything to the SVG // We plan on changing this, so we can test this in the future it.skip('shows a custom icon', () => { }); it('passes additional props', () => { render(_jsx(ErrorMessage, { "aria-hidden": false, "data-test": "data-test", id: "id" })); const component = screen.getByRole('paragraph'); expect(component).toHaveAttribute('aria-hidden', 'false'); expect(component).toHaveAttribute('id', 'id'); expect(component).toHaveAttribute('data-test', 'data-test'); }); });