how to wait the acynchronus scrollIntoView without using cy.wait(XXX) or comparing view/element heights?
Here is what i thought to be like:
const cyBrick = cy.get(selector);
cyBrick.scrollIntoView().then( _ => {
cyBrick
.then(([$brick]) => {
const brickBody = $brick.getBoundingClientRect();
cyBrick.trigger('mousedown', {which: 1, pageX: brickBody.x, pageY: brickBody.y});
...
});
});
In my case i'm testing dragAndDrop so i need
- to scroll to an element to be dragged;
- mouseDown on the element
- scroll to target container and so on...
Also i tried a custom command
//commands.js
Cypress.Commands.add('scrollIntoViewAndUseThen', {prevSubject: true}, (subject) => {
cy.wrap(subject).scrollIntoView().as('scrolling');
cy.wait('@scrolling');
});
//mytest.spec.js
cyBrick.scrollIntoViewAndUseThen().then( _ => ...
But roots only are allowed to use @;
At this moment i use workaround with wait
cyBrick.scrollIntoView().wait(500)
PS: i read in docs that scrollToView allows to chain should accertion only