Skip to content

Testing drag and drop in framer motion using cypress. #2858

Answered by jamesvec
jamesvec asked this question in Q&A
Discussion options

You must be logged in to vote

Leaving this here for anyone who needs to do this.

cy.get('[data-cy=drag-target]')
  .eq(0)
  .then(($el) => {
    const el = $el[0];
    const rect = el.getBoundingClientRect();
    cy.wrap($el).trigger('pointerdown', {
      clientX: rect.left + rect.width / 2,
      clientY: rect.top + rect.height / 2,
      button: 0,
    });
  });

cy.get('[data-cy=drag-target]')
  .eq(1)
  .then(($el) => {
    const el = $el[0];
    const rect = el.getBoundingClientRect();
    cy.wrap($el).trigger('pointermove', {
      clientX: rect.left + rect.width / 2,
      clientY: rect.top + rect.height / 2,
      button: 0,
    });
    cy.wrap($el).trigger('pointerup', {
      clientX: rect.left + rect.width / 

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by jamesvec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant