Reactjs 如何验证在开玩笑时轻触已调用或未调用的函数?

Reactjs 如何验证在开玩笑时轻触已调用或未调用的函数?,reactjs,react-native,jestjs,ts-jest,Reactjs,React Native,Jestjs,Ts Jest,这是我的代码看起来像的 export function myComponent(user: type) { -------------- return ( <TouchableWithoutFeedback testID="notificationCard" onPress={() => navigation.navigate(NEW_ROUTES.profile, { id: rawId })}

这是我的代码看起来像的

export function myComponent(user: type) {
    --------------

   return (
     <TouchableWithoutFeedback 
        testID="notificationCard"
        onPress={() => navigation.navigate(NEW_ROUTES.profile, { id: rawId })}
              >
        <Card style={styles.stackedCard} ></Card>
    <TouchableWithoutFeedback />

  )
} 

这回答了你的问题吗?你可以使用spyOn
jest.spyOn(导航,'navigate')
这能回答你的问题吗?您可以使用spyOn
jest.spyOn(导航,'navigate')
  const { environment, getByTestId } = renderWithNavigation(myComponent);
  const notificationCards = getByTestId("notificationCards");
  const notificationCard = getAllByTestId(notificationCards, "notificationCard");
  fireEvent.press(notificationCard[0]);
  expect(notificationCard[0]).toHaveBeenCalled();