Closed
Description
I'm trying to figure out why it seems like the fireEvent.press
function always seem to trigger a callback even though it shouldn't be registered. My use case is that I'm trying to write a test that makes sure that onPress
isn't called if the component is "disabled".
Trying to mimic the behaviour below...
const MyComponent = _props => (
<View>
<TouchableHighlight testID={'touchable'}>
<Text>{'Foo'}</Text>
</TouchableHighlight>
</View>
)
const pressedCallback = jest.fn()
const { getByTestId } = render(<MyComponent onPress={() => pressedCallback('bar')} />)
fireEvent.press(getByTestId('touchable'))
expect(pressedCallback).not.toBeCalled() //Expected mock function not to be called but it was called with: ["bar"]