import { render } from '@testing-library/react';
import { Label } from './Label';
import { describe, it, expect } from 'vitest';
describe('Label', () => {
it('renders null when children and description are falsy', () => {
const { container } = render(
);
expect(container.firstChild).toBeNull();
});
it('renders a label without description', () => {
const { getByText, queryByText } = render(
<>
>
);
const label = getByText('Name');
expect(label).toBeInTheDocument();
expect(label.closest('label')).toHaveAttribute('for', 'kze792d8');
const description = queryByText('This is a label');
expect(description).not.toBeInTheDocument();
});
it('renders a label with description and no label', () => {
const { container, queryByText } = render(
);
const label = container.querySelector('label');
expect(label).toBeInTheDocument();
expect(label).toHaveAttribute('for', 'kze792d8');
const description = queryByText('This is a label');
expect(description).toBeInTheDocument();
});
});