No handler function found with fireEvent.press on disabled TouchableOpacity
See original GitHub issueDescribe the bug
When running fireEvent.press
on a disabled TouchableOpacity, the following error appears: No handler function found for event: "press"
Expected behavior
Should not raise an error
Steps to Reproduce
Run the following
import { TouchableOpacity } from 'react-native'
describe.only('Test TouchableOpacity', () => {
const Button = ({ onPress }) => {
return <TouchableOpacity testID='testBtn' disabled={true} onPress={onPress}></TouchableOpacity>
}
const onPressSpy = sinon.spy()
it('onPress does not trigger', () => {
const { getByTestId } = render( <Button onPress={onPressSpy}/>)
fireEvent.press(getByTestId('testBtn'))
expect(props.onPress.callCount).toBe(0)
})
})
Versions
npmPackages:
@testing-library/react-native: ^7.0.0 => 7.0.0
react: 16.13.1 => 16.13.1
react-native: 0.63.0 => 0.63.0
react-test-renderer: ^16.13.0 => 16.13.1
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (6 by maintainers)
Top Results From Across the Web
react native - No handler function found for event: "changeText"
The error occurs because there's no onChangeText callback in your TextInput so there's no handler to call when triggering fireEvent.
Read more >react testing library disabled button - You.com | The Search Engine ...
When running fireEvent.press on a disabled TouchableOpacity, the following error appears: No handler function found for event: "press" ...
Read more >API | React Native Testing Library - Open Source
Useful function to help testing components that use hooks API. By default any render , update , fireEvent , and waitFor calls are...
Read more >How to use the react-testing-library.fireEvent.change function ...
To help you get started, we've selected a few react-testing-library.fireEvent.change examples, based on popular ways it is used in public projects.
Read more >React Native touchable vs. pressable components
Later, the framework introduced the Pressable API for handling ... Adjust the pressed opacity level with the activeOpacity prop; Disable the ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Andarius I think your original complain is a valid point. So
fireEvent
throws error when it does not find any matching event handler, which should suggested to the programmer that there is a problem with assertions or components under test.However the case when there is event handler but is disabled should probably be handled without throwing error.
We’ve just released 7.0.1 which now doesn’t throw. So please adjust your tests to something like this: