Created
May 7, 2024 13:40
-
-
Save BollaBerg/312e697e06ff0624441303cc4a0edff2 to your computer and use it in GitHub Desktop.
React testing-library method for testing drag-and-drop functionality
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { fireEvent } from '@testing-library/react'; | |
function dragElementTo(element: HTMLElement, target: HTMLElement) { | |
fireEvent.dragStart(element); | |
fireEvent.dragEnter(target); | |
fireEvent.dragOver(target, { clientX: 1, clientY: 1 }); | |
fireEvent.dragEnd(element, { dataTransfer: { dropEffect: 'copy' } }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment