这是我的代码看起来像
export function myComponent(user: type) {
--------------
return (
<TouchableWithoutFeedback
testID="notificationCard"
onPress={() => navigation.navigate(NEW_ROUTES.profile, { id: rawId })}
>
<Card style={styles.stackedCard} ></Card>
<TouchableWithoutFeedback />
)
}
在这里我需要验证onPress里面的函数 我不知道该怎么做,但我试过了
测试.tsx
const { environment, getByTestId } = renderWithNavigation(myComponent);
const notificationCards = getByTestId("notificationCards");
const notificationCard = getAllByTestId(notificationCards, "notificationCard");
fireEvent.press(notificationCard[0]);
expect(notificationCard[0]).toHaveBeenCalled();