import React from 'react'; import { render, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { Checkbox } from '../Checkbox'; describe('Checkbox', () => { test('controlled', () => { const { asFragment } = render(); expect(asFragment()).toMatchSnapshot(); }); test('controlled - 3rd state', () => { const { asFragment } = render(); expect(asFragment()).toMatchSnapshot(); }); test('uncontrolled', () => { const { asFragment } = render(); expect(asFragment()).toMatchSnapshot(); }); test('isDisabled', () => { const { asFragment } = render(); expect(asFragment()).toMatchSnapshot(); }); test('label is string', () => { const { asFragment } = render(); expect(asFragment()).toMatchSnapshot(); }); test('label is function', () => { const functionLabel = () =>

Header

; const { asFragment } = render(); expect(asFragment()).toMatchSnapshot(); }); test('label is node', () => { const { asFragment } = render(Header} id="check" isChecked aria-label="check" />); expect(asFragment()).toMatchSnapshot(); }); test('passing class', () => { const { asFragment } = render( ); expect(asFragment()).toMatchSnapshot(); }); test('passing HTML attribute', () => { const { asFragment } = render( ); expect(asFragment()).toMatchSnapshot(); }); test('passing description', () => { render(); expect(screen.getByText('Text description...')).toBeInTheDocument(); }); test('passing body', () => { render(); expect(screen.getByText('This is where custom content goes.')).toBeInTheDocument(); }); test('checkbox onChange handler called when component is clicked', async () => { const onChangeHandler = jest.fn(); const user = userEvent.setup(); render(); await user.click(screen.getByLabelText('check')); expect(onChangeHandler).toHaveBeenCalled(); }); test('should throw console error when no id is given', () => { const myMock = jest.fn(); global.console = { ...global.console, error: myMock }; render(); expect(myMock).toHaveBeenCalled(); }); test('renders component wrapper as span', () => { const { container } = render( ); const span = container.querySelector('span'); expect(span).toHaveClass('pf-v5-c-check'); }); });