Skip to content

Instantly share code, notes, and snippets.

@claudiainbytes
Created February 11, 2026 19:00
Show Gist options
  • Select an option

  • Save claudiainbytes/d2cbb87bdb0a9a5a5be891246e5bb7bb to your computer and use it in GitHub Desktop.

Select an option

Save claudiainbytes/d2cbb87bdb0a9a5a5be891246e5bb7bb to your computer and use it in GitHub Desktop.
Testing Drag and Drop
import { fireEvent } from '@testing-library/react'
it('permite drag and drop de items', async () => {
const user = userEvent.setup()
render(<DraggableList />)
const item1 = screen.getByText('Item 1')
const item2 = screen.getByText('Item 2')
// Simular drag and drop
fireEvent.dragStart(item1)
fireEvent.dragEnter(item2)
fireEvent.dragOver(item2)
fireEvent.drop(item2)
fireEvent.dragEnd(item1)
// Verificar nuevo orden
const items = screen.getAllByRole('listitem')
expect(items[0]).toHaveTextContent('Item 2')
expect(items[1]).toHaveTextContent('Item 1')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment