Skip to content

Commit

Permalink
fix: try trick for code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
long-lazuli committed Mar 21, 2023
1 parent 43bd6aa commit cb2258c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 6 additions & 2 deletions packages/circuit-ui/components/Checkbox/Checkbox.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,21 @@ describe('Checkbox', () => {
});

it('should render with indeterminate styles', () => {
const { container } = render(
const { container, getByRole } = render(
<Checkbox indeterminate {...defaultProps} />,
);
expect(container).toMatchSnapshot();
const inputEl = getByRole('checkbox') as HTMLInputElement;
expect(inputEl.indeterminate).toBeTruthy();
});

it('should render with indeterminate styles even when checked', () => {
const { container } = render(
const { container, getByRole } = render(
<Checkbox checked indeterminate {...defaultProps} />,
);
expect(container).toMatchSnapshot();
const inputEl = getByRole('checkbox') as HTMLInputElement;
expect(inputEl.indeterminate).toBeTruthy();
});

it('should render with invalid styles and an error message', () => {
Expand Down
8 changes: 3 additions & 5 deletions packages/circuit-ui/components/Checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,11 @@ export const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(

const localRef = useRef<HTMLInputElement>(null);
useEffect(() => {
if (!localRef.current) {
return;
if (localRef.current) {
localRef.current.indeterminate = indeterminate;
}

localRef.current.indeterminate = indeterminate;
// Because it came from a props, we are keeping the `indeterminate` state even if the `checked` one is changed:
}, [props.defaultChecked, props.checked, indeterminate]);
}, [props.checked, indeterminate]);

return (
<CheckboxWrapper className={className} style={style} disabled={disabled}>
Expand Down

0 comments on commit cb2258c

Please sign in to comment.