Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

Failed Testing Switch React Native with Testing Library

$
0
0

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");

Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>