mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix checked callback attribute value
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
parent
9f25212f45
commit
b8e56dfba5
@ -48,4 +48,24 @@ describe("<Switch/>", () => {
|
||||
|
||||
expect(onClick).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("returns true checked attribute in a onChange callback", () => {
|
||||
const onClick = jest.fn();
|
||||
const { getByTestId } = render(<Switch onChange={onClick} checked={true}/>);
|
||||
const switcher = getByTestId("switch");
|
||||
|
||||
fireEvent.click(switcher);
|
||||
|
||||
expect(onClick).toHaveBeenCalledWith(false, expect.any(Object));
|
||||
});
|
||||
|
||||
it("returns false checked attribute in a onChange callback", () => {
|
||||
const onClick = jest.fn();
|
||||
const { getByTestId } = render(<Switch onChange={onClick}/>);
|
||||
const switcher = getByTestId("switch");
|
||||
|
||||
fireEvent.click(switcher);
|
||||
|
||||
expect(onClick).toHaveBeenCalledWith(true, expect.any(Object));
|
||||
});
|
||||
});
|
||||
|
||||
@ -17,7 +17,13 @@ export function Switch({ children, disabled, onChange, ...props }: SwitchProps)
|
||||
return (
|
||||
<label className={cssNames(styles.Switch, { [styles.disabled]: disabled })} data-testid="switch">
|
||||
{children}
|
||||
<input type="checkbox" role="switch" disabled={disabled} onChange={(event) => onChange?.(props.checked, event)} {...props}/>
|
||||
<input
|
||||
type="checkbox"
|
||||
role="switch"
|
||||
disabled={disabled}
|
||||
onChange={(event) => onChange?.(!props.checked, event)}
|
||||
{...props}
|
||||
/>
|
||||
</label>
|
||||
);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user