import { render, screen } from '@testing-library/react' import userEvent from '@testing-library/user-event' // index.spec.tsx import { describe, expect, it, vi } from 'vitest' import Group from '../component/group' import Radio from '../index' describe('Radio (index)', () => { it('attaches Group as a property on the default export', () => { expect(Radio.Group).toBe(Group) }) it('renders Radio when used as a component', () => { render(RootLabel) expect(screen.getByText('RootLabel')).toBeInTheDocument() const label = screen.getByText('RootLabel') expect(label.tagName.toLowerCase()).toBe('label') }) it('Radio.Group provides context to nested Radio and group onChange is called on click', async () => { const user = userEvent.setup() const groupOnChange = vi.fn() render( InnerRadio , ) const root = screen.getByText('InnerRadio').closest('div') as HTMLElement await user.click(root) expect(groupOnChange).toHaveBeenCalledTimes(1) expect(groupOnChange).toHaveBeenCalledWith('val') }) it('Radio.Group can render arbitrary children', () => { render( {}}>
child
, ) expect(screen.getByTestId('plain-child')).toBeInTheDocument() }) })