Skip to content

Commit

Permalink
Merge pull request #15 from acastSthlm/en/feat/mouse-events
Browse files Browse the repository at this point in the history
Add mouse over and mouse out helpers
  • Loading branch information
emilnordh authored Mar 5, 2018
2 parents 60b2e6b + 01b6dd2 commit 78395be
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "acast-test-helpers",
"version": "14.0.0",
"version": "14.1.0",
"description": "A bunch of helper methods that greatly simplify asynchronous unit and acceptance testing of front end web apps.",
"main": "dist/index.js",
"scripts": {
Expand Down
24 changes: 24 additions & 0 deletions src/acceptance.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,30 @@ export function mouseMove(selector, options) {
triggerMouseEvent(mouseMove, selector, options);
}

/**
* Waits for an element to show up, and then simulates a user mouse over by triggering a mouse event on that element.
* @param {string|jQuery} selector The jQuery selector or jQuery object to simulate mouse move on.
* Note that the selector or jQuery object must represent exactly one (1) element in the app, or the call will fail.
* @param {object} [options] Any options to pass along to the simulated mouse event.
* @example
* mouseDown('.element-to-mouse-move-on', { clientX: 1337, clientY: 1338 });
*/
export function mouseOver(selector, options) {
triggerMouseEvent(mouseOver, selector, options);
}

/**
* Waits for an element to show up, and then simulates a user mouse out by triggering a mouse event on that element.
* @param {string|jQuery} selector The jQuery selector or jQuery object to simulate mouse move on.
* Note that the selector or jQuery object must represent exactly one (1) element in the app, or the call will fail.
* @param {object} [options] Any options to pass along to the simulated mouse event.
* @example
* mouseDown('.element-to-mouse-move-on', { clientX: 1337, clientY: 1338 });
*/
export function mouseOut(selector, options) {
triggerMouseEvent(mouseOut, selector, options);
}

/**
* Waits for an element to show up, and then simulates a user touch start by triggering a touch event on that element.
* @param {string|jQuery} selector The jQuery selector or jQuery object to simulate touch on.
Expand Down
4 changes: 4 additions & 0 deletions tests/acceptance/mouse-events.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
mouseDown,
mouseUp,
mouseMove,
mouseOver,
mouseOut,
setupAsync,
andThen,
jQuery as $
Expand Down Expand Up @@ -31,6 +33,8 @@ describe('Mouse Events', () => {
describeMouseEventHelper(mouseDown, 'mousedown');
describeMouseEventHelper(mouseUp, 'mouseup');
describeMouseEventHelper(mouseMove, 'mousemove');
describeMouseEventHelper(mouseOver, 'mouseover');
describeMouseEventHelper(mouseOut, 'mouseout');

function describeMouseEventHelper(helperToTest, eventName, extraTests = ()=> {
}) {
Expand Down

0 comments on commit 78395be

Please sign in to comment.