Skip to content

No handler function found with fireEvent.press on disabled TouchableOpacity #469

Closed
@Andarius

Description

@Andarius

Describe 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 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions