@amsterdam/design-system-react
Version:
All React components from the Amsterdam Design System. Use it to compose pages in your website or application.
46 lines (45 loc) • 1.98 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
/**
* @license EUPL-1.2+
* Copyright Gemeente Amsterdam
*/
import { render } from '@testing-library/react';
import { createRef } from 'react';
import { describe, expect, it } from 'vitest';
import { Field } from './Field';
describe('Field', () => {
it('renders', () => {
const { container } = render(_jsx(Field, {}));
const component = container.querySelector(':only-child');
expect(component).toBeInTheDocument();
expect(component).toBeVisible();
});
it('renders a design system BEM class name', () => {
const { container } = render(_jsx(Field, {}));
const component = container.querySelector(':only-child');
expect(component).toHaveClass('ams-field');
});
it('renders an extra class name', () => {
const { container } = render(_jsx(Field, { className: "extra" }));
const component = container.querySelector(':only-child');
expect(component).toHaveClass('ams-field extra');
});
it('renders with the error class', () => {
const { container } = render(_jsx(Field, { invalid: true }));
const component = container.querySelector(':only-child');
expect(component).toHaveClass('ams-field--invalid');
});
it('supports ForwardRef in React', () => {
const ref = createRef();
const { container } = render(_jsx(Field, { ref: ref }));
const component = container.querySelector(':only-child');
expect(ref.current).toBe(component);
});
it('passes additional props', () => {
const { container } = render(_jsx(Field, { "aria-hidden": "false", "data-test": "data-test", id: "id" }));
const component = container.querySelector(':only-child');
expect(component).toHaveAttribute('aria-hidden', 'false');
expect(component).toHaveAttribute('id', 'id');
expect(component).toHaveAttribute('data-test', 'data-test');
});
});