P粉3846792662023-09-01 20:43:25
Since you don't want to test Swiper itself and just want to verify that your handler executes when onSlideChange is triggered, you can follow these steps:
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'));