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'));