Bird
0
0

You want to test a drag-and-drop feature using cypress-real-events. Which sequence of commands correctly simulates dragging an element with id drag-item to a target with id drop-zone?

hard📝 Application Q8 of 15
Cypress - Plugins and Ecosystem
You want to test a drag-and-drop feature using cypress-real-events. Which sequence of commands correctly simulates dragging an element with id drag-item to a target with id drop-zone?
Acy.get('#drag-item').realType('drag').realClick('#drop-zone');
Bcy.get('#drag-item').realClick().realHover('#drop-zone').realClick();
Ccy.get('#drag-item').realMouseDown().realMouseMove('#drop-zone').realMouseUp();
Dcy.get('#drag-item').realHover().realClick('#drop-zone').realType('drop');
Step-by-Step Solution
Solution:
  1. Step 1: Understand drag-and-drop native events

    Dragging involves pressing mouse down, moving the mouse, then releasing mouse up on the target.
  2. Step 2: Match commands to drag sequence

    cy.get('#drag-item').realMouseDown().realMouseMove('#drop-zone').realMouseUp(); correctly uses realMouseDown(), realMouseMove() to the target, and realMouseUp() to simulate drag-and-drop.
  3. Final Answer:

    cy.get('#drag-item').realMouseDown().realMouseMove('#drop-zone').realMouseUp(); -> Option C
  4. Quick Check:

    Drag = mouseDown + mouseMove + mouseUp [OK]
Quick Trick: Drag needs mouseDown, mouseMove, then mouseUp in order [OK]
Common Mistakes:
  • Using click instead of mouseDown/mouseUp
  • Typing text instead of mouse events
  • Hovering without mouseDown

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes