P粉3846792662023-09-01 20:43:25
由於您不想測試Swiper本身,只想驗證當onSlideChange被觸發時,您的處理程序是否執行,您可以按照以下步驟進行:
jest.mock('swiper/react', () => ({ Swiper: ({ children, onSlideChange }: { children: React.ReactNode; onSlideChange: () => void }) => ( <div data-testid="swiper" onClick={onSlideChange}> {children} </div> ), }));
fireEvent.click(screen.getByTestId('swiper'));