Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test dnd-kit with Jest and React Testing Library #72

Closed
Thebarda opened this issue Jan 27, 2021 · 2 comments
Closed

Test dnd-kit with Jest and React Testing Library #72

Thebarda opened this issue Jan 27, 2021 · 2 comments

Comments

@Thebarda
Copy link

Hello there !

I'm trying to drag and drop element with Jest and React Testing Library. I'm using @dnd-kit/sortable.
I configure my sensors to listen to pointer events and keyboard events. When I testing on a browser both sensore works perfectly but within a Jest / React Testing Library these sensors does'nt work anymore.

For the keyboard way:

  • I press "Enter" on drag handle
  • I press "ArrowDown" (vertical list)
  • I press "Enter" to finish drag and drop process

For the pointer way. I use the dragStart, dragOver and drop function from React Testing Library.

My question Is : Is there a way to test drag and drop in Jest + React Testing Library environment ? Or should I use Cypress ?

@clauderic
Copy link
Owner

Your best bet if you want to test real user-like drag and drop interactions would be Cypress yes. With Jest your tests should focus on the api surface exposed by <DndContext> and how your app re-renders as a result.

@mgolawski
Copy link

mgolawski commented Apr 16, 2021

@clauderic How would you proceed with triggering handlers on DnDContext?. Firing RTL events does not trigger anything. It basically closes the way to unit test any behavior until extracting the logic outside of components.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants