Help me please...
I have a React Native custom Button component that receives an onPress prop and passes that onPress to a TouchableNativeFeedback. I make a unit testing with @testing-library/react-native. I try to spy on onPress, to check if it is triggered when the TouchableNativeFeedback is touched. Somehow the spy function is not called when I simulate press event on the Button. Is there any mistake in my implementation?
FI: This behavior only occurs in TouchableNativeFeedback, but working perfectly with Button
Here is my implementation:
Button.js
const Button = ({onPress, label}) => (
<TouchableNativeFeedback onPress={onPress} testID="button">
<View style={someStyling}>
<Text>{label}</Text>
</View>
</TouchableNativeFeedback>
)
export default Button
Button.test.js
it("Fire onPress props when button pressed", () => {
const mockFn = jest.fn();
const { getByTestId } = render(<Button onPress={mockFn} />);
const button = getByTestId("button");
fireEvent.press(button);
expect(mockFn).toHaveBeenCalled();
});