question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Trying to drag and drop with Cypress

See original GitHub issue

Hi !

I would like to test my application with Cypress but I can’t find a way to simulate a drag and drop. I tried to use the same mouseMoveBy command you created in draggable_spec.ts, but it has no effect on my application. Nothing seems to move.

I just have a basic drag and drop setup from the DndKit getting started documentation, nothing fancy. Did you have to setup something special to make it work with Cypress?

I’m not sure if I can use Cypress with Code Sandbox so I can link a reproductive example. I’ll investigate.

Thank you

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
igutocommented, Apr 22, 2021

hi, @damien-monni

I had similar issue and found a solution. in your dnd-kit-issue repository, try this:

diff --git a/src/App.js b/src/App.js
index 0eee1ee..766a14c 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,10 +1,13 @@
-import { useDroppable, useDraggable, DndContext } from "@dnd-kit/core";
+import { useDroppable, useDraggable, DndContext, MouseSensor, useSensor, useSensors } from "@dnd-kit/core";
 import { useState } from "react";

 const Draggable = () => {
   const { attributes, listeners, setNodeRef, transform } = useDraggable({
     id: "draggable",
   });
+  const sensors = useSensors(
+    useSensor(MouseSensor),
+  )

   return (
     <div style={{ display: "flex" }}>
@@ -62,9 +65,13 @@ const Root = ({ isDropped }) => {

 function App() {
   const [isDropped, setIsDropped] = useState(false);
+  const sensors = useSensors(
+    useSensor(MouseSensor),
+  )

   return (
     <DndContext
+      sensors={sensors}
       onDragEnd={(event) => {
         if (event.over?.id) {
           setIsDropped(true);

It seems like MouseSensor is necessary. I hope this helps.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Implement Drag and Drop in Cypress - Testup.io
Method 2: Using “DragStart” to move elements ... Alternatively, we can perform drag-and-drop tests in Cypress using the DragStart method. This method does...
Read more >
Cypress code-snippet#1- Drag and Drop feature
Approach 1: Using events such as dragstart, drop and dragend we can successfully achieve drag and drop. Create a new DataTransfer object, which...
Read more >
How to implement drag and drop in cypress test?
get(dragSelector).should('exist') in function drag won't guard against async loading, Commands just tell Cypress "put this test in the ...
Read more >
Drag and Drop in Cypress - Automated Visual Testing
Learn how to simulate drag and drop actions in Cypress. ... Drag and drop is a common tool that gives developers the ability...
Read more >
A cypress child command for drag'n'drop support. - GitHub
The drag command is a child command. The command only accepts elements. As the drop target simply pass a selector as a string....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found