How do you test with handleSubmit and fireEvent? #1966
-
Using
I'm testing a screen for a simple form submission. What I expect is a network call, with a response. What's Happeningconst onSubmit = async formData => {
await ApiService.put('greet', formData);
};
// ...
<Button
accessibilityLabel="Continue"
disabled={isDisabled}
onPress={handleSubmit(onSubmit)}
isLoading={isLoading}
>
Continue
</Button> I'm expecting a log from the console from the network request in this test. server.put('/greet', (server, request) => {
console.log('request', JSON.parse(request.requestBody));
});
const {
getByLabelText,
} = render(<EnterPhoneNumberScreen />);
let input = getByLabelText('Phone Number');
let button = getByLabelText('Continue');
await fireEvent.changeText(input, { nativeEvent: { text: '123-123-1234' } })
await fireEvent.press(button); The event seems to get swallowed by This works when removing handleSubmit: <Button
accessibilityLabel="Continue"
disabled={isDisabled}
onPress={onSubmit}
isLoading={isLoading}
>
Continue
</Button> I tested whether or not |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
for react-native you will need to stub window object. This will be part of the FAQ in the new doc
|
Beta Was this translation helpful? Give feedback.
for react-native you will need to stub window object. This will be part of the FAQ in the new doc