使用Cypress內建的trigger方法實現拖拽一個元素到另一個同型別元素,實現排序
Typescript實現方法:
export function dragAndDrop(sourceLocator: string, targetLocator: string) {
const dataTranferMock = { setData: () => {}, setDragImage: () => {} }
cy.get(sourceLocator)
.trigger('pointerdown', { button: 0 })
.trigger('dragstart',{dataTransfer: dataTranferMock});
cy.get(targetLocator)
.trigger('dragover')
.trigger('drop');
}