drag-mock
Trigger HTML5 drag & drop events for testing
Requirements
No 3rd party libraries required. All you need is a plain website and an ES5 compatible browser (e.g. IE9+, Chrome, Firefox, ...).
Setup
Browser
Just add the library script to your page
You can then use it as a window global or as an AMD module
// plain javascriptvar dragSource = document;var dropTarget = document; dragMock; // AMD;
Node / Webpack
Install using
npm install drag-mock --save-dev
and require it in your code
var dragMock = ;
Usage
var dragSource = document;var dropTarget = document;var hoverRegion = document; dragMock ;
If you would like to set some properties on the event object you may pass an optional properties object as second parameter:
var dragSource = document;var dropTarget = document; dragMock ;
You can also customize the events by passing an optional callback function. The callback is called after creating the event, but before dispatching it. If your callback takes less than two arguments then it will be called once for the dragstart/drop event. It will be called for all events created if the callback takes two arguments:
dragMock ;
Testing
Use it with the testing framework of your choice.
;
Additional features
The following events are provided with a fake (but fully functional) dataTransfer object:
drag
, dragstart
, dragover
, dragend
, dragleave
, drop
webdriver.io integration
If you are running Selenium tests using webdriver.io and you need drag & drop functionality beyond Selenium's dragAndDrop() you can easily integrate drag-mock into webdriver. CSS selectors and XPath strings are both accepted as arguments.
var dragMock = ;var webdriverio = ; var webdriver = webdriverio; // set up webdriver.dragStart(), webdriver.dragOver(), webdriver.dragLeave() and webdriver.drop()dragMock; // load the drag-mock library into the browser contextdragMock; // drag and dropwebdriver ;
Development
First run npm install
to install all dependencies. gulp dist
rebuilds the dist/ contents. gulp test
(or npm test
) runs the test suite. The default gulp task first runs dist
, then test
.
License
This software is licensed under the terms of the MIT license. See LICENSE for details.