I'm getting the following error when trying to simulate an event using fireEvent "onChange" : "TypeError: Cannot read property 'value' of undefined"
My component :
const [isActive, setIsActive] = useState<boolean>(policy_value); const handleChangeSwitch = () => { const value = !isActive; settingsService.updatePolicy(id, value); setIsActive(!isActive); };<Switch value={isActive} onChange={handleChangeSwitch} testID="policy-switch"/>
My test:
const { getByTestId } = render(<Policy data={mockPolicy} />);let switchButton = getByTestId("policy-switch")fireEvent(switchButton, "onChange", { value: true });expect(settingsService.updatePolicy).toHaveBeenCalled();
I tried:
fireEvent(switchButton, "onChange", { value: true });fireEvent(switchButton, "onChange", true);fireEvent(switchButton, "onChange");