Skip to content

Commit

Permalink
fix: properly test untyped selectable box sets (#2736)
Browse files Browse the repository at this point in the history
  • Loading branch information
brian-smith-tcril authored Oct 20, 2023
1 parent 46f8d85 commit 63d4640
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/SelectableBox/tests/SelectableBoxSet.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import '@testing-library/jest-dom/extend-expect';
import userEvent from '@testing-library/user-event';
import SelectableBox from '..';

const boxText = (text) => `SelectableBox${text}`;

const checkboxType = 'checkbox';
const checkboxText = (text) => `SelectableCheckbox${text}`;

Expand All @@ -12,6 +14,16 @@ const radioText = (text) => `SelectableRadio${text}`;

const ariaLabel = 'test-default-label';

function SelectableBoxSet(props) {
return (
<SelectableBox.Set name="box" ariaLabel={ariaLabel} {...props}>
<SelectableBox value={1}>{boxText(1)}</SelectableBox>
<SelectableBox value={2}>{boxText(2)}</SelectableBox>
<SelectableBox value={3}>{boxText(3)}</SelectableBox>
</SelectableBox.Set>
);
}

function SelectableCheckboxSet(props) {
return (
<SelectableBox.Set name={radioType} type={checkboxType} ariaLabel={ariaLabel} {...props}>
Expand Down Expand Up @@ -68,11 +80,8 @@ describe('<SelectableBox.Set />', () => {
expect(screen.getByTestId('checkbox-set')).toBeInTheDocument();
});
it('renders with radio type if neither checkbox nor radio is passed', () => {
const originalError = console.error;
console.error = jest.fn();
render(<SelectableCheckboxSet type="text" data-testid="radio-set" />);
render(<SelectableBoxSet data-testid="radio-set" />);
expect(screen.getByTestId('radio-set')).toBeInTheDocument();
console.error = originalError;
});
it('renders with radio type', () => {
render(<SelectableRadioSet type={radioType} data-testid="radio-set" />);
Expand Down

0 comments on commit 63d4640

Please sign in to comment.